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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:45:22  来源:igfitidea点击:

How do I Add a Tooltip To a DataGridTextColumn

wpfdatagridtooltipdatagridtextcolumn

提问by J Burnett

I'm using WPFtoolkit DataGrid,I have to wrap text in a DataGridTextColumnor I have to add a ToolTipto 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 DataGridTextColumnbut you can easily use the DataGridTemplateColumnand the ToolTipServiceinstead. e.g.

我不确定您是否可以向 a 添加工具提示,DataGridTextColumn但您可以轻松地使用DataGridTemplateColumnToolTipService代替。例如

<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.Abbreviationis 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 应用程序。