我需要为标签创建一个ToolTip
,该标签始终是Label大小的两倍。我无法获得正确的工具提示。
我的代码在这里;我已经包含了一个复杂的模板,但是如果我使用字符串值,问题是相同的:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="200" Title="MainWindow">
<Window.Resources>
<ControlTemplate x:Key="Density">
<StackPanel>
<TextBlock Text="" />
<Separator Margin="2,0" BorderBrush="Black" />
<TextBlock Text="³" />
</StackPanel>
</ControlTemplate>
<TransformGroup x:Key="DoubleSize">
<ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2" ScaleY="2" />
<SkewTransform />
<RotateTransform />
<TranslateTransform />
</TransformGroup>
<Style x:Key="TTipStyle" TargetType="ToolTip">
<Setter Property="RenderTransform" Value="{StaticResource DoubleSize}"/>
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="HasDropShadow" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate >
<Grid Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" Background="AliceBlue">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Label HorizontalAlignment="Center" VerticalAlignment="Center" Template="{StaticResource Density}">
<Label.ToolTip>
<ToolTip RenderTransform="{StaticResource DoubleSize}" Background="AliceBlue" Style="{StaticResource TTipStyle}" Template="{StaticResource Density}" />
</Label.ToolTip>
</Label>
<ContentControl HorizontalAlignment="Left" VerticalAlignment="Top" Template="{StaticResource Density}" RenderTransform="{StaticResource DoubleSize}"/>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Top" Text="::---- THIS SIZE TOOLTIP"/>
</Grid>
</Window>
我应该如何为工具提示定义一种样式,该样式的大小范围要足以容纳完整的双倍标签内容?
答案 0 :(得分:1)
将RenderTransform移出ToolTip标签本身...
<ToolTip Background="AliceBlue" Style="{StaticResource TTipStyle}" Template="{StaticResource Density}" />
...然后按照您的样式删除RenderTransform和Template并设置LayoutTransform:
<Style x:Key="TTipStyle" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="HasDropShadow" Value="True" />
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="2" ScaleY="2" />
</Setter.Value>
</Setter>
</Style>