1
votes

I have a Datagrid in one of mine controls and a Style set in a Resource Dictionary file. In order to see the ToolTip, I use Setter in the Style:

<Style TargetType="{x:Type DataGridColumnHeader}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="ToolTipService.ToolTip" Value="{Binding}"/>

In the Control with DataGrid, where I use this Style, I have tried to set a specific text for the ToolTip in each Column Header, but it doesn’t work. The ToolTip is always showing the same text as the text in the Header:

<DataGridTextColumn x:Name="iEnumberColumn" Binding="{Binding IEnumber}"  Width="100" Header="Column A" ToolTipService.ToolTip="Column A Tooltip"  />

I have tried to RelativeSource Self, Dynamic and Static resources, but neither one works. Also if I don’t have Setter in the Style, ToolTip doesn’t appears at all. If I use additional Style inside my control, it works but I’m losing the original Style set in the Dictionary.

Could you please suggest how to set the ToolTip in the Style in order to add a specific text when I define each DataGrid Column?

1
Yes, I have found the solution on this link. It is simple, just changed the Header to a TextBlock and set the ToolTip for the TextBlock. I don’t need to do anything in the Resource Dictionary file. Thank you!v31

1 Answers

4
votes

Probably this is not the only way, but I found a simple solution. I replaced the code below:

<DataGridTextColumn x:Name="iEnumberColumn" Binding="{Binding IEnumber}"  Width="100" Header="Column A" ToolTipService.ToolTip="Column A Tooltip"  />

with this one:

<DataGridTextColumn x:Name="iEnumberColumn" Binding="{Binding IEnumber}"  Width="100" >
    <DataGridTextColumn.Header>
        <TextBlock Text="ColumnA" ToolTip="Column A Tooltip"/>
    </DataGridTextColumn.Header>
</DataGridTextColumn>

And I removed the Setter for the ToolTip from the Resource Dictionary file.