所以我一直在嘗試覆寫滑塊的默認樣式,但我覺得我一直這樣做的方式是不正確的。一方面,我希望能夠突出拇指背后的軌跡。我該如何以正確的方式做到這一點?
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style BasedOn="{StaticResource {x:Type Slider}}"
TargetType="Slider"
x:Key="SliderTheme">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Slider">
<Grid>
<Border VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Height="5"
Background="White"/>
<Track x:Name="PART_Track">
<Track.Thumb>
<Thumb x:Name="PART_Thumb">
<Thumb.Template>
<ControlTemplate>
<Border Height="20"
Width="20"
Background="#fff"
CornerRadius="15"/>
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Track.Thumb>
</Track>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
</ResourceDictionary>
uj5u.com熱心網友回復:
您可以像這樣更改軌道的顏色。
- 通過右鍵單擊
Slider并選擇Edit template然后Edit a copy...獲取默認樣式。 - 更改顏色為
<SolidColorBrush x:Key="SliderThumb.Track.Background" Color="HotPink"/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/513549.html
