WPF DataGridTextColumn Tooltip

Is there a way to add a tooltip to the DataGridColumn header and maintain the sorting functionality. The following code does not work (it does not display a hint)

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

Column loses sorting functionality .. Help!

+4
source share
4 answers

When the grid creates automatic columns, it knows which field is displayed in this column. When you create a column yourself, the data grid does not know what data you will display in this column, and therefore it cannot guess which field to sort the column. To create a column that you define yourself, add the SortMemberPath property to your DataGridTemplateColumn as follows:

 <DataGridTemplateColumn Header="Test" Width="70" SortMemberPath="TestText"> ... </DataGridTemplateColumn> 
+4
source

To display the ToolTip in a DataGridColumnHeader , you need to bind the ToolTip property to it ToolTip its DataGridColumn , as shown

 <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> 
+7
source

You add a tooltip to the column template, not the heading.

Have you tried setting the HeaderStyle property to a DataGridColumn in the style containing the template, including the tooltip for HeaderCell?

See also this example.

0
source

The previous answers are mostly correct, however I find them too complicated or considering only one of the two publishing issues.

First, you can always set the SortPath property to save the sort for the DataGridTemplateColumn or, possibly, to sort a property other than the displayed one.

Secondly, you do not need a DataGridTemplateColumn to have a hint in the column header, as indicated in the OP. You can use the template column if you want to add a tooltip to the actual cell (but this is probably not necessary either). In any case, adding a tooltip to the column heading is most easily done using the HeaderStyle element

 <DataGridTextColumn Header="Test" Binding="{Binding TestText}"> <DataGridTextColumn.HeaderStyle> <Style TargetType="DataGridColumnHeader"> <Setter Property="ToolTip" Value="Test ToolTip" /> </Style> </DataGridTextColumn.HeaderStyle> </DataGridTextColumn> 
0
source

Source: https://habr.com/ru/post/1337551/


All Articles