我为我的应用程序创建了自定义滑块和拇指模板。它的工作正常,除了PART_SelectionRange矩形之外,该矩形从拇指后面略微开始,并且到达最大值时明显落后于它。
我不知道如何解决这个问题,因为看起来问题在控制PART_SelectionRange矩形大小的任何类的行为中。
(抱歉,我不知道如何内联它)。
我不知道如何解决这个问题,因为看起来问题在控制PART_SelectionRange矩形大小的任何类的行为中。
<ControlTemplate x:Key="SliderThumbHorizontalDefault" TargetType="{x:Type Thumb}">
<Grid>
<!-- SliderThumb -->
<Path x:Name="grip" Data="M-0.4,6.4 C1.2,1 9,1 10.5,6.5 12,11.787571 5.0267407,18.175417 5.0267407,18.175417 5.0267407,18.175417 -2,11.8 -0.4,6.4 z"
Fill="White" Stretch="Fill" SnapsToDevicePixels="True"
Stroke="Black" StrokeThickness="1" UseLayoutRounding="True" />
<ContentPresenter Margin="0 4 0 0" Content="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type Slider}}}" TextBlock.Foreground="Black" TextBlock.FontSize="20" TextBlock.TextAlignment="Center" />
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="SliderHorizontal" TargetType="{x:Type Slider}">
<ControlTemplate.Resources>
<vc:TickConverter x:Key="TickConverter" />
</ControlTemplate.Resources>
<Grid Height="{StaticResource SliderHeight}">
<Border x:Name="TrackBackground" BorderBrush="{StaticResource SliderThumb.Track.Border}" BorderThickness="0"
Background="White"
CornerRadius="{Binding ActualHeight, Converter={StaticResource HalvingConverter}, ElementName=TrackBackground}">
<!-- This rectangle is what lags behind! -->
<Rectangle x:Name="PART_SelectionRange" Fill="SlateBlue"
HorizontalAlignment="Left" RadiusY="3" RadiusX="3" />
</Border>
<Track x:Name="PART_Track" >
<Track.Thumb>
<Thumb x:Name="Thumb" Focusable="False" Width="35" Height="47" OverridesDefaultStyle="True"
Template="{StaticResource SliderThumbHorizontalDefault}" Margin="-14.65,-55,-16,12"/>
</Track.Thumb>
</Track>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelectionRangeEnabled" Value="true">
<Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="Foreground" TargetName="Thumb" Value="Blue" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="{x:Type Slider}">
<Setter Property="MinHeight" Value="{StaticResource SliderHeight}" />
<Setter Property="MaxHeight" Value="{StaticResource SliderHeight}" />
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false" />
<Setter Property="IsSelectionRangeEnabled" Value="True" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Foreground" Value="{StaticResource SliderThumb.Static.Foreground}" />
<Setter Property="SelectionStart" Value="{Binding Minimum, RelativeSource={RelativeSource Self}}" />
<Setter Property="SelectionEnd" Value="{Binding Value, RelativeSource={RelativeSource Self}}" />
<Setter Property="Template" Value="{StaticResource SliderHorizontal}" />
</Style>
此时,我不知道应该尝试修改什么。我相信我已经尝试从xaml更改了每个有意义的属性,所以我认为问题在于Slider类,但是无法理解具体问题出在哪里。