76

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

KornMuffin
  • 2,887
  • 3
  • 32
  • 48

2 Answers2

146

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>
J Burnett
  • 1,579
  • 1
  • 9
  • 5
  • for anyone on Silverlight, see [@MarkGladdling's answer](http://stackoverflow.com/a/1977545/80428) – Jay Wick Dec 16 '15 at 01:39
  • 4
    FYI, I struggled with this for a while until I realized that if "IsHitTestVisible" is set to FALSE on the datagrid tooltips don't work. – Mageician Feb 05 '16 at 18:22
  • Can you add image and/or edit the background of the tooltip somehow when using this approach? – ajr Feb 02 '18 at 14:26
  • If you want the tooltip only at the column header, use `DataGridTextColumn.HeaderStyle` and the style's `TargetType="DataGridColumnHeader"`. – Jiří Skála Dec 12 '22 at 16:45
24

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.

g t
  • 7,287
  • 7
  • 50
  • 85
Mark Gladding
  • 241
  • 2
  • 3
  • 1
    This also works in Silverlight, got here from top 3 hits from google search. Of course change xml ns to 'sdk:' instead of 'data:' if your code matches the latest SL xaml templates. – yzorg May 19 '11 at 17:35
  • Although I don't work with Silverlight, that is the only answer which also worked for me. The most popular answer results an exception in my application. – Endery Dec 01 '17 at 08:56