Мне нужно создать ToolTip для метки, которая всегда в два раза больше метки. Мне не удалось получить правильный размер всплывающей подсказки.
Мой код здесь; Я включил сложный шаблон, но проблема та же, если я использую строковое значение:
<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>
Как мне определить стиль для всплывающей подсказки, размеры которой достаточно велики, чтобы вместить полное содержимое метки двойного размера?





Уберите свой 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>