【发布时间】:2019-02-02 13:24:04
【问题描述】:
我有这种样式来向数据网格的每一行中的单元格添加工具提示。问题是所有工具提示都具有相同的文本(第一行的文本)。我做错了什么?
<DataGridTextColumn Header="Profit (%)"
Binding="{Binding Percentage, StringFormat=N8}">
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}"
BasedOn="{StaticResource {x:Type DataGridCell}}">
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip>
<ToolTip.ContentTemplate>
<DataTemplate>
<TextBlock Text="{Binding Content.Text, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridCell}}}" />
</DataTemplate>
</ToolTip.ContentTemplate>
</ToolTip>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
但如果我使用简单的工具提示,它就完美了
<DataGridTextColumn Header="Profit (%)"
Binding="{Binding Percentage, StringFormat=N8}">
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}"
BasedOn="{StaticResource {x:Type DataGridCell}}">
<Setter Property="ToolTip"
Value="{Binding Percentage}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
【问题讨论】: