我的问题很简单我希望Slider控件下面有一些标签。我在网上找到了一些有趣的解决方案,尤其是这个 Labels under slider 要求编辑Thumb但是当我使用它在数据下面给出如此多的涂鸦的样式时,我无法使它工作。
我也一直试图在混合中使用模板。我能够在Slider中更改Ticks的颜色,但是当我在文本块中放置一些文本时,我期望它会根据Ticks的数量重复标签,但我看到一个文本块。
任何人都可以帮我查看链接中发布的样式,甚至可以编辑我的样式。这是我到目前为止的代码。
<ControlTemplate
x:Key="SliderHorizontal"
TargetType="{x:Type Slider}">
<Border
x:Name="border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto"
MinHeight="{TemplateBinding MinHeight}" />
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TickBar
x:Name="TopTick"
Fill="{TemplateBinding Foreground}"
Height="4"
Margin="0,0,0,2"
Placement="Top"
Grid.Row="0"
Visibility="Collapsed" />
<TickBar
x:Name="BottomTick"
Fill="{TemplateBinding Foreground}"
Height="4"
Margin="0,2,0,0"
Placement="Bottom"
Grid.Row="2"
Visibility="Collapsed" />
<TextBlock
x:Name="tblSomething"
Text="Hello"
Grid.Row="3" Foreground="Black"
></TextBlock>
<Border
x:Name="TrackBackground"
BorderBrush="{StaticResource SliderThumb.Track.Border}"
BorderThickness="1"
Background="{StaticResource SliderThumb.Track.Background}"
Height="4.0"
Margin="5,0"
Grid.Row="1"
VerticalAlignment="center">
<Canvas
Margin="-6,-1">
<Rectangle
x:Name="PART_SelectionRange"
Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
Height="4.0"
Visibility="Hidden" />
</Canvas>
</Border>
<Track
x:Name="PART_Track"
Grid.Row="1">
<Track.DecreaseRepeatButton>
<RepeatButton
Command="{x:Static Slider.DecreaseLarge}"
Style="{StaticResource RepeatButtonTransparent}" />
</Track.DecreaseRepeatButton>
<Track.IncreaseRepeatButton>
<RepeatButton
Command="{x:Static Slider.IncreaseLarge}"
Style="{StaticResource RepeatButtonTransparent}" />
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb
x:Name="Thumb"
Focusable="False"
Height="18"
OverridesDefaultStyle="True"
Template="{StaticResource SliderThumbHorizontalDefault}"
VerticalAlignment="Center"
Width="11" />
</Track.Thumb>
</Track>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger
Property="TickPlacement"
Value="TopLeft">
<Setter
Property="Visibility"
TargetName="TopTick"
Value="Visible" />
<Setter
Property="Template"
TargetName="Thumb"
Value="{StaticResource SliderThumbHorizontalTop}" />
<Setter
Property="Margin"
TargetName="TrackBackground"
Value="5,2,5,0" />
</Trigger>
<Trigger
Property="TickPlacement"
Value="BottomRight">
<Setter
Property="Visibility"
TargetName="BottomTick"
Value="Visible" />
<Setter
Property="Fill"
TargetName="BottomTick"
Value="Orange" />
<Setter
Property="Template"
TargetName="Thumb"
Value="{StaticResource SliderThumbHorizontalBottom}" />
<Setter
Property="Margin"
TargetName="TrackBackground"
Value="5,0,5,2" />
</Trigger>
<Trigger
Property="TickPlacement"
Value="Both">
<Setter
Property="Visibility"
TargetName="TopTick"
Value="Visible" />
<Setter
Property="Visibility"
TargetName="BottomTick"
Value="Visible" />
</Trigger>
<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>