我正在尝试更改AvalonEdit中滚动条的拇指颜色。我尝试了多种方法:
设置ScrollViewer的样式-有很多示例,但是我大部分都无法编译,而当我这样做时,它们将无法工作。
使用FindTemplate并在运行时更改拇指颜色。在许多但并非所有情况下都有效。
我想要的只是改变拇指的颜色。快来WPF,给我扔骨头。
请有人使我摆脱痛苦,并告诉我如何。
跟进:
通过更改默认的拇指样式,我可以得到大多数想要的东西:
<UserControl.Resources>
<Style x:Key="{x:Type Thumb}"
TargetType="{x:Type Thumb}">
<Setter Property="Opacity" Value="0.1" />
</Style>
</UserControl.Resources>
但是,如果尝试向此样式添加控件模板,则它没有任何效果。每次我认为我了解WPF样式时,都会发生一些事情使我确信我一无所知。
基于此页:msdn
您可以执行以下操作:
<Style TargetType="{x:Type Thumb}" x:Key="ScrollBarThumb">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border CornerRadius="2"
Background="Black"
BorderBrush="Red"
BorderThickness="1" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ScrollBar">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition MaxHeight="18" />
<RowDefinition Height="0.00001*" />
<RowDefinition MaxHeight="18" />
</Grid.RowDefinitions>
<Border Grid.RowSpan="3" />
<RepeatButton Grid.Row="0"
Command="ScrollBar.LineUpCommand"
Content="M 0 4 L 8 4 L 4 0 Z" />
<Track x:Name="PART_Track" Grid.Row="1" IsDirectionReversed="true">
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="1,0,1,0"/>
</Track.Thumb>
</Track>
<RepeatButton Grid.Row="3"
Command="ScrollBar.LineDownCommand"
Content="M 0 0 L 4 4 L 8 0 Z" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句