How do I Add a Tooltip To a DataGridTextColumn

佐手、 提交于 2019-11-30 07:43:03

问题


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...


回答1:


Yes, you can add tooltip text to DataGridTextColumn - just stylize it

<DataGridTextColumn Header="ScreenName" Binding="{Binding ScreenName}" >
    <DataGridTextColumn.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="ToolTip" Value="{Binding Name}" />
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>



回答2:


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.

<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.

Note: This example was taken from a Silverlight 3.0 application.



来源:https://stackoverflow.com/questions/1164288/how-do-i-add-a-tooltip-to-a-datagridtextcolumn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!