我在 WPF DataGrid 中显示工具提示,但我想自定义它的宽度,使其不大于包含数据的单元格的大小。我尝试将路径设置为“宽度”和“实际宽度”,但它都忽略了它们。我究竟做错了什么?
<DataGridTextColumn Binding="{Binding Description}" Header="Message" Width="*">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="ToolTipService.ShowDuration" Value="60000" />
<Setter Property="ToolTip">
<Setter.Value>
<TextBlock TextWrapping="Wrap"
Width="{Binding RelativeSource={RelativeSource AncestorType=DataGridCell}, Path=ActualWidth}"
Text="{Binding Description}" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>