WPF DataGridTextColumn Tooltip

developer picture developer · Jan 28, 2011 · Viewed 10.6k times · Source

Is there a way to add tool tip to DataGridColumn header and still retain the sorting functionality. The below code doesnt work(It doesnt display the tooltip)

<toolkit:DataGridTextColumn Header="Test" Width="70" Binding="{Binding TestText}" ToolTipService.ToolTip="{Binding TestText}">

And when I use the code below

<toolkit:DataGridTemplateColumn Header="Test" Width="70">  
              <toolkit:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding TestText}" ToolTip="{Binding TestText}"  />
                        </DataTemplate>
                    </toolkit:DataGridTemplateColumn.CellTemplate>
                </toolkit:DataGridTemplateColumn>

The column loses sorting functionality..Help!

Answer

Fredrik Hedblad picture Fredrik Hedblad · Jan 29, 2011

To get the ToolTip to display in the DataGridColumnHeader you'll need to bind the ToolTip property for it to the ToolTip of its DataGridColumn like this

<toolkit:DataGridTextColumn Header="Test"
                            Width="70"
                            Binding="{Binding TestText}"
                            ToolTipService.ToolTip="My Tooltip Text">
    <toolkit:DataGridTextColumn.HeaderStyle>
        <Style TargetType="toolkit:DataGridColumnHeader">
            <Setter Property="ToolTip"
                    Value="{Binding RelativeSource={RelativeSource Self},
                                    Path=Column.(ToolTipService.ToolTip)}"/>
        </Style>
    </toolkit:DataGridTextColumn.HeaderStyle>
</toolkit:DataGridTextColumn>