wpf 如何向 DataGridTextColumn 添加工具提示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1164288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I Add a Tooltip To a DataGridTextColumn
提问by J Burnett
I'm using WPFtoolkit DataGrid
,I have to wrap text in a DataGridTextColumn
or
I have to add a ToolTip
to the text column. I have searched the net but i couldn't get a proper solution. Expecting your valuable suggestions...
我正在使用 WPFtoolkit DataGrid
,我必须将文本包裹在 a 中,DataGridTextColumn
或者我必须将 a 添加ToolTip
到文本列中。我已经在网上搜索过,但我找不到合适的解决方案。期待您的宝贵建议...
回答by J Burnett
Yes, you can add tooltip text to DataGridTextColumn - just stylize it
是的,您可以将工具提示文本添加到 DataGridTextColumn - 只需对其进行样式化
<DataGridTextColumn Header="ScreenName" Binding="{Binding ScreenName}" >
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip" Value="{Binding Name}" />
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
回答by Mark Gladding
I'm not sure if you can add a tooltip to a DataGridTextColumn
but you can easily use the DataGridTemplateColumn
and the ToolTipService
instead. e.g.
我不确定您是否可以向 a 添加工具提示,DataGridTextColumn
但您可以轻松地使用DataGridTemplateColumn
和ToolTipService
代替。例如
<data:DataGrid.Columns>
<data:DataGridTemplateColumn Header="Broker">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Moniker.Abbreviation}"
ToolTipService.ToolTip="{Binding Moniker.Name}" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
In this example Moniker.Abbreviation
is displayed in the column. When the user hovers over a cell, the full broker name (Moniker.Name
) is displayed in the tooltip.
在本例Moniker.Abbreviation
中显示在列中。当用户将鼠标悬停在单元格上时,完整的经纪人名称 ( Moniker.Name
) 会显示在工具提示中。
Note: This example was taken from a Silverlight 3.0 application.
注意:此示例取自 Silverlight 3.0 应用程序。