这是我的自定义拇指,用于滑块:
<Style x:Key="SliderThumbStyle" TargetType="Thumb">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="false"/>
<Setter Property="Height" Value="18"/>
<Setter Property="Width" Value="18"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Grid>
<Border x:Name="thumbBorder"
CornerRadius="9,0,0,9"
Background="DimGray"/>
<Ellipse x:Name="thumbEllipse"
Fill="Orange"></Ellipse>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这就是我在滑块自定义控件中使用它的方式:
<Style TargetType="Slider">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Value" Value="5"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Slider">
<Grid>
<Border Name="PART_Border"
CornerRadius="9"
Width="{TemplateBinding Width}"
Height="18"
Background="Red"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />
<Track Name="PART_Track"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}">
<Track.DecreaseRepeatButton>
<RepeatButton Command="Slider.DecreaseLarge"
Style="{StaticResource SliderButtonStyle}" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb x:Name="myThumb"
Style="{StaticResource SliderThumbStyle}" />
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Command="Slider.IncreaseLarge"
Style="{StaticResource DecreaseSliderButtonStyle}"/>
</Track.IncreaseRepeatButton>
</Track>
</Grid>
<!-- this is the part I would like to change, so I can modify myThumb's border / ellipse: -->
<ControlTemplate.Triggers>
<Trigger SourceName="PART_Track" Property="Value" Value="10">
<Setter TargetName="myThumb" Property="Width" Value="50"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
在评论部分,当达到最大值时,我设法通过触发器修改拇指:有什么办法可以修改自定义拇指的部分,比如它的边框(x:thumbBorder)或椭圆(x:thumbEllipse )?