I’m trying to create datagrid tooltip entirely in code behind file.
Tooltip XAML code looks like this:
<data:DataGrid>
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="My Header">
<data:DataGridTextColumn.HeaderStyle>
<Style TargetType="dataprimitives:DataGridColumnHeader">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<ContentControl Content="{Binding}">
<ToolTipService.ToolTip>
<ToolTip Content="My Tooltip"></ToolTip>
</ToolTipService.ToolTip>
</ContentControl>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</data:DataGridTextColumn.HeaderStyle>
</data:DataGridTextColumn>
</data:DataGrid.Columns>
I’m stuck at the <Setter Property="ContentTemplate">. My current code:
Style style = new Style();
style.TargetType = typeof(DataGridColumnHeader);
Setter setter = new Setter();
setter.Property = DependencyProperty.Register("ContentTemplate", typeof(DataTemplate), typeof(FrameworkElement), null);
Anyone could show me an example of implementing this part in code behind:
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<ContentControl Content="{Binding}">
<ToolTipService.ToolTip>
<ToolTip Content="My Tooltip"></ToolTip>
</ToolTipService.ToolTip>
</ContentControl>
</DataTemplate>
</Setter.Value>
</Setter>
Thank you!
Once you have got the handle for the column to which you want to add the tooltip then you try below.
Now that you have defined you tooltip value then you can set the HeaderStyle property of the column something like this…
where dgCustDetails is the datagrid’s name.