我利用工具提示顯示網格中每一行的更多詳細信息。 細節顯示爲工具提示內的網格列,但我無法更改工具提示寬度以將它們全部顯示出來。UWP - 更改工具提示高度/寬度
我試着改變工具提示Width,MinWidth,MaxWidth屬性,甚至內部網格寬度;但工具提示始終保持相同的大小。
.CS
Rectangle rect = new Rectangle();
rect.Opacity = 0.3;
rect.SetValue(Grid.RowProperty, r);
rect.SetValue(Grid.ColumnSpanProperty, 7);
rect.Fill = new SolidColorBrush(Colors.Azure);
rect.Margin = new Thickness(2);
MyTooltip mt = new MyTooltip(par);
mt.Style = Application.Current.Resources["LargeToolTipStyle"] as Style;
rect.SetValue(ToolTipService.ToolTipProperty, mt);
STYLES.XAML
<Style x:Key="LargeToolTipStyle" TargetType="local:MyTooltip">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<ContentPresenter
x:Name="LayoutRoot"
MaxWidth="800"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{TemplateBinding ContentTransitions}"
TextWrapping="Wrap">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="OpenStates">
<VisualState x:Name="Closed">
<Storyboard>
<FadeOutThemeAnimation TargetName="LayoutRoot" />
</Storyboard>
</VisualState>
<VisualState x:Name="Opened">
<Storyboard>
<FadeInThemeAnimation TargetName="LayoutRoot" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</ContentPresenter>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
MYTOOLTIP.XAML
<UserControl
x:Class="Client.MyTooltip"
...
d:DesignHeight="300"
d:DesignWidth="400">
<Grid Name="TooltipGrid" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Name="TooltipHeaderTBL" Text="LEFT HEADER"
Grid.Column="0">
</TextBlock>
<TextBlock Name="TooltipHeaderTBR" Text="RIGHT HEADER"
Grid.Column="1">
</TextBlock>
<TextBlock Name="TooltipContentTBL" Text="Content sample (L)"
Grid.Row="1"
Grid.Column="0"></TextBlock>
<TextBlock Name="TooltipContentTBR" Text="Content sample (R)"
Grid.Row="1"
Grid.Column="1"></TextBlock>
</Grid>
</UserControl>
請提供您的XAML以更好地瞭解您如何嘗試這樣做。請閱讀如何用[mcve]提問。 – AVK
能否請你解釋爲什麼這個帖子已經被降低後添加新的細節? – Tiresia