Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a tooltip for a datagrid header, where the header text is generated dynamically?

I need to add a tooltip for a column header of a DataGrid (Silverlight 4). I will generate the number of columns and column header text dynamically.

GridColumnCreation(....)
{
    IEnumerable allHeaderText = /* Linq query */; 
}

How to use this collection to set a tooltip?

like image 312
Mohan Avatar asked Jan 06 '11 12:01

Mohan


3 Answers

This can be done even more simply than in @Farukh's answer:

<data:DataGridTextColumn.HeaderStyle>
  <Style TargetType="DataGridColumnHeader">
    <Setter Property="ToolTipService.ToolTipProperty"
            Value="Your tool tip here" />
  </Style>
</data:DataGridTextColumn.HeaderStyle>

Or, if you need to do it in code:

var style = new Style(typeof(DataGridColumnHeader));
style.Setters.Add(new Setter(ToolTipService.ToolTipProperty,
                             "Your tool tip here"));
column.HeaderStyle = style;
like image 95
Drew Noakes Avatar answered Nov 01 '22 01:11

Drew Noakes


In case it might help anyone. It works when using TooTip property.

<DataGridTextColumn.HeaderStyle>
    <Style TargetType="DataGridColumnHeader">
        <Setter Property="ToolTip" Value="{Binding}"/>
    </Style>
</DataGridTextColumn.HeaderStyle>
like image 29
oloopy Avatar answered Nov 01 '22 02:11

oloopy


If you do not want to create a new style for the Header, simply add a TextBlock for your column header and set the tooltip on it.

<DataGridTextColumn>
    <DataGridTextColumn.Header>
        <TextBlock Text="ColumnA" ToolTip="ColumnA Tooltip"/>
    </DataGridTextColumn.Header>
</DataGridTextColumn>
like image 10
YantingChen Avatar answered Nov 01 '22 01:11

YantingChen