14

I tried the following:

<tk:DataGridTextColumn 
    Header="Item" 
    Binding="{Binding Item.Title}" 
    ToolTipService.ToolTip="{Binding Item.Description}" />

And I don't see any tool tip.

Any ideas? Is it even implemented?

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632

5 Answers5

29

This works for me:

<Style TargetType="{x:Type Custom:DataGridColumnHeader}">
   <Style.Triggers>
      <Trigger Property="IsMouseOver" Value="True">
          <Setter Property="ToolTip" Value="{Binding Column.(ToolTipService.ToolTip), RelativeSource={RelativeSource Self}}"/>
      </Trigger>
   </Style.Triggers>
</Style>
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
Boris
  • 306
  • 2
  • 2
  • Brilliant! This small Style now makes the Tooltips appear, no messing around with having to change DataGridColumnHeaders into DataGridTextColumns or anything. Exactly what I was looking for! – Mike Gledhill Nov 29 '10 at 10:45
  • 1
    Hey can you tell me how you add the above style to DataGridComboBoxColumn – Abhi May 08 '12 at 08:51
8

pls, check if the code below would work for you, it should be displaying tooltips for columns headers and cells, cell's tooltip should be bent the Description field of the data object:

<DataGridTextColumn Width="SizeToCells"   
                    MinWidth="150" 
                    Binding="{Binding Name}">

    <DataGridTextColumn.Header>
        <TextBlock Text="Name" ToolTipService.ToolTip="Header ToolTip" />
    </DataGridTextColumn.Header>

    <DataGridTextColumn.ElementStyle>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="ToolTip" Value="{Binding Description}" />
            <Setter Property="TextWrapping" Value="Wrap" />
        </Style>
    </DataGridTextColumn.ElementStyle>
</DataGridTextColumn>

solution found here: 5 Random Gotchas with the WPF DataGrid

serge_gubenko
  • 20,186
  • 2
  • 61
  • 64
6

The DataGridTextColumn is not visible. You have to set tooltips on the header or the content.

To set a ToolTip on the header, change the Header to a TextBlock:

<tk:DataGridTextColumn
  Binding="{Binding Item.Title}">
  <tk:DataGridTextColumn.Header>
    <TextBlock
      Text="Text" 
      ToolTipService.ToolTip="Tooltip for header" />
  </tk:DataGridTextColumn.Header>
</tk:DataGridTextColumn>

To set a ToolTip on the column contents, set it in the Style:

<tk:DataGridTextColumn
  Binding="{Binding Item.Title}"
  Heading="Text">
  <tk:DataGridTextColumn.ElementStyle>
    <Style>
      <Setter Property="ToolTipService.ToolTip" Value="{Binding Item.Description}" />
    </Style>
  </tk:DataGridTextColumn.ElementStyle>
</tk:DataGridTextColumn>

You may also want to set EditingElementStyle.

Ray Burns
  • 62,163
  • 12
  • 140
  • 141
1

Additionally, if your column is a DataGridTemplateColumn instead of a DataGridTextColumn, you can do it like this:

<DataGridTemplateColumn x:Name="MyCheckBoxColumn" CellStyle="{StaticResource MyCellStyle}" >
    <DataGridTemplateColumn.HeaderTemplate>
        <DataTemplate>
            <TextBlock Text="MyHeaderName" ToolTip="This is my column description" />
        </DataTemplate>
    </DataGridTemplateColumn.HeaderTemplate>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox ... />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
CowboyBebop
  • 701
  • 7
  • 10
0

Set ToolTipService.ToolTip Property in Header style:

<Setter Property="ToolTipService.ToolTip" Value="{x:Static res:StringResources.List_Dialog_SelectAll_Checkbox}"/>

Here it is how I used it when I had image in DataGridCheckBoxColumn instead of text. XAML:

    <Window x:Class="MyProject.GUI.ListDialog"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:viewModel="clr-MyProject.GUI.ViewModels" 
            Title="{Binding Title}"  Height="350" Width="650"
            MinHeight="350" MinWidth="650"
            xmlns:res="clr-MyProject.GUI.Resources" Closing="Window_Closing" WindowStyle="ToolWindow">
    <Window.Resources>
            <BitmapImage x:Key="MyImageSource" UriSource="Resources/Images/SelectDeselect.png" />
           <Style x:Key="CheckBoxHeader"  TargetType="DataGridColumnHeader">
                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                <Setter Property="VerticalContentAlignment" Value="Center"/>
                            <Setter Property="ToolTipService.ToolTip" Value="{x:Static res:StringResources.List_Dialog_SelectAll_Checkbox}"/>
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <Image Width="15" Height="15" Source="{StaticResource MyImageSource}" />
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    </Window.Resources>

C#:

DataGridCheckBoxColumn checkColumn = new DataGridCheckBoxColumn();
checkColumn.HeaderStyle = new System.Windows.Style();
checkColumn.CanUserSort = checkColumn.CanUserResize = false;
checkColumn.Width = new DataGridLength(25);
checkColumn.HeaderStyle = (Style)Resources["CheckBoxHeader"];
checkColumn.CellStyle = (Style)Resources["CenterAlignedCellStyle"];
checkColumn.IsReadOnly = false;
dataGrid.Columns.Add(checkColumn);
ticky
  • 363
  • 2
  • 12