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?
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;
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With