Unable to set DataGridColumn's ToolTip
Asked Answered
W

5

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?

Webby answered 14/11, 2009 at 20:58 Comment(0)
G
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>
Genoa answered 12/1, 2010 at 20:41 Comment(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!Snifter
Hey can you tell me how you add the above style to DataGridComboBoxColumnBruxelles
N
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

Negative answered 15/11, 2009 at 2:20 Comment(0)
C
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.

Cusick answered 15/11, 2009 at 2:21 Comment(0)
B
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>
Bonny answered 19/8, 2011 at 16:11 Comment(0)
I
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);
Itacolumite answered 7/7, 2011 at 12:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.