我是 wpf 的新手。我有一个带有多个滑块的窗口,我想显示与拇指相邻的滑块的值 AutoToolTipPlacement 的行为方式,除了我希望它始终可见。
我已经尝试了几种不同的方法,但没有一个是完全正确的。
解决方案
<Track.Thumb>
<Thumb x:Name="Thumb" Focusable="False" Height="18" OverridesDefaultStyle="True" VerticalAlignment="Center" Width="11">
<Thumb.Template>
<ControlTemplate TargetType="{x:Type Thumb}">
<Grid HorizontalAlignment="Center" UseLayoutRounding="True" VerticalAlignment="Center">
<Path x:Name="grip" Data="M0,0C0,0 11,0 11,0 11,0 11,18 11,18 11,18 0,18 0,18 0,18 0,0 0,0z" Fill="#FFF0F0F0" Stretch="Fill" SnapsToDevicePixels="True" Stroke="#FFACACAC" StrokeThickness="1" UseLayoutRounding="True" VerticalAlignment="Center"/>
<TextBox HorizontalAlignment="Left" Height="18" Margin="-12,-23,-13,0" TextWrapping="Wrap" Text="{Binding Value, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Slider}}}" VerticalAlignment="Top" Width="36" TextAlignment="Center" Background="{x:Null}" BorderBrush="{x:Null}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Fill" TargetName="grip" Value="#FFDCECFC"/>
<Setter Property="Stroke" TargetName="grip" Value="#FF7EB4EA"/>
</Trigger>
<Trigger Property="IsDragging" Value="True">
<Setter Property="Fill" TargetName="grip" Value="#FFDAECFC"/>
<Setter Property="Stroke" TargetName="grip" Value="#FF569DE5"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Fill" TargetName="grip" Value="#FFF0F0F0"/>
<Setter Property="Stroke" TargetName="grip" Value="#FFD9D9D9"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Thumb.Template>
</Thumb>