How do I Add a Tooltip To a DataGridTextColumn

WpfDatagridTooltipDatagridtextcolumn

Wpf Problem Overview


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

Wpf Solutions


Solution 1 - Wpf

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>

Solution 2 - Wpf

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionsreeejith unnikrishnanView Question on Stackoverflow
Solution 1 - WpfJ BurnettView Answer on Stackoverflow
Solution 2 - WpfMark GladdingView Answer on Stackoverflow