Okej to może inaczej ciężko mi podpiąć ten twój styl bo dużo w nim brakuje innych stylów. Ale analogiczny przykład mam styl dla Slider
i styl dla Thumb
, oraz samo wywołanie.
A więc cały kod:
<UserControl x:Class="WpfApplication1.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Style x:Key="ThumbBall" TargetType="{x:Type Thumb}">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Path StrokeThickness="0.550000" Stroke="#FFA2A2A2" StrokeMiterLimit="1.000000"
Data="F1 M 0,3.455078 C 0,1.615723 1.490234,0.125000 3.330078,0.125000 C 5.168945,0.125000 6.659179,1.615723 6.659179,3.455078 C 6.659179,5.292969 5.168945,6.784180 3.330078,6.784180 C 1.490234,6.784180 0,5.292969 0,3.455078 Z"
x:Name="TrackBall" Opacity="0.75" Fill="{DynamicResource MouseOverBrush}" />
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="TrackBall" Property="Opacity" Value="1" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="TrackBall" Property="Opacity" Value="0.7" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="SliderStyle" TargetType="{x:Type Slider}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Slider}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" MinHeight="{TemplateBinding Slider.MinHeight}" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!--<Path Margin="0,0,0,0" Grid.Row="1" Fill="{DynamicResource SliderTrack}" Data="F1 M 0,2.701660 L 0,4.179688 L 970.306641,4.179688 L 970.306641,2.701660 L 0,2.701660 Z" />-->
<Rectangle Stretch="Fill" Grid.Row="1" Height="2" Fill="{DynamicResource SliderTrack}" />
<Track Grid.Row="1" Name="PART_Track" Visibility="Visible">
<Track.DecreaseRepeatButton>
<RepeatButton Visibility="Hidden"
Command="Slider.DecreaseLarge" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Margin="15,0,15,0" Style="{StaticResource ThumbBall}" />
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Visibility="Hidden"
Command="Slider.IncreaseLarge" />
</Track.IncreaseRepeatButton>
</Track>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<Slider Style="{StaticResource SliderStyle}" Width="500" Height="100" />
</Grid>
</UserControl>
Style pożyczyłem z:
http://tlo.googlecode.com/svn/trunk/GenArtWPF/source/GenArt.Client/Resources/ControlTemplates/Slider.xaml
http://tlo.googlecode.com/svn/trunk/GenArtWPF/source/GenArt.Client/Resources/ColorsAndBrushes.xaml <-- Zmieniłem tylko dwa kolory dla paska i kulki.
Efekt:
