WPF Listview ScrollBar 样式

<Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowStartupLocation="CenterScreen"
  Title="" SizeToContent="WidthAndHeight">
  <Window.Resources>
   
    <Style x:Key="scroll_thumb_style" TargetType="{x:Type Thumb}">
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="IsTabStop" Value="false"/>
            <Setter Property="Focusable" Value="false"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Thumb">
                        <Rectangle Width="13" Fill="#7D7D7D" RadiusX="5" RadiusY="5">
                        </Rectangle>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    <ControlTemplate x:Key="scroll_background" TargetType="{x:Type RepeatButton}">
                           <Border Background="Transparent">
                            </Border>
                        </ControlTemplate> 
    <Style TargetType="ScrollBar">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ScrollBar">
                                <Grid Width="15">
                                    <Border Width="13" HorizontalAlignment="Center" CornerRadius="5" Background="#33555555">
                                    </Border>
                                    <Track HorizontalAlignment="Center" Name="PART_Track" Width="{TemplateBinding Width}" Maximum="{TemplateBinding Maximum}" Minimum="{TemplateBinding Minimum}"
                                    Value="{TemplateBinding Value}"  IsDirectionReversed="true">
                                        <Track.DecreaseRepeatButton>
                                            <RepeatButton Template="{StaticResource scroll_background}" Command="ScrollBar.LineUpCommand"  />
                                        </Track.DecreaseRepeatButton>
                                        <Track.IncreaseRepeatButton>
                                            <RepeatButton Template="{StaticResource scroll_background}" Command="ScrollBar.LineDownCommand" />
                                        </Track.IncreaseRepeatButton>
                                        <Track.Thumb>
                                            <Thumb Style="{StaticResource scroll_thumb_style}" >
                                            </Thumb>
                                        </Track.Thumb>
                                    </Track>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
  </Window.Resources>
  <Grid>  
     <ScrollViewer  Height="300">
        <Border Width="500" Height="500" Background="LightBlue"></Border>
     </ScrollViewer>
  </Grid>
</Window>

 

 

ListVIew 为ItemsControl,任何属于ItemsControl的控件,DataGrid,ListBox等  ,都默认支持ScrollViewer的,不需要特定去修改它。

 

转载于:https://www.cnblogs.com/wgscd/articles/9056459.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值