17,748
社区成员
发帖
与我相关
我的任务
分享

<Style x:Key="ScrollBar_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>
<ControlTemplate x:Key="scroll_background" TargetType="RepeatButton">
<Border Background="Transparent">
</Border>
</ControlTemplate>
<Style x:Key="scroll_thumb_style" TargetType="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>
</Window.Resources>
折腾了好久就是不会用,脑子笨

只是,单修改ScrollViewer 这个控件的style,我是会的,就是不会修改ListView的滚动条。就是我现在有个ListView,当数据比较多的时候会显示滚动条,我是想把现在这个style应用到ListView的滚动条上去,怎么用呢?
<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>