【发布时间】:2010-07-29 18:41:33
【问题描述】:
我正在尝试将数据网格单元格的工具提示设置为等于该单元格中 TextBlock 内的文本。我到目前为止是这样的:
<Style x:Key="CellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
<Grid>
<TextBlock Margin="2" VerticalAlignment="Center"
HorizontalAlignment="Left" TextWrapping="Wrap" >
<ContentPresenter Content="{TemplateBinding Property=ContentControl.Content}" />
<TextBlock.ToolTip>
<ContentPresenter Content="{TemplateBinding Property=ContentControl.Content}" />
</TextBlock.ToolTip>
</TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
但是,它所做的是非常简短地显示工具提示,然后删除单元格中的内容,因此根本没有显示任何内容。此外,从模板设置器外部设置工具提示是一个选项,但我不确定当前绑定是什么。
【问题讨论】:
-
试试这个:
-
这会导致它在您将鼠标悬停在单元格上时崩溃。它抛出一个 InvalidOperationException:“指定元素已经是另一个元素的逻辑子元素。先断开它。”