Nothing like answering an old question with your own...
I was inspired by @Scroog1's answer but seems a bit redundant having a Tooltip
which just mimics the content that is there. You usually want the Tooltip
because you've abbreviated the column header text.
I created a small AttachedProperty
which I set my Tooltip
value on the GridViewColumn
. I then bind
to this from my Style
for my GridViewColumnHeader
.
Now I just define the Style
once, and add it and the AttachedProperty
where I want to use it.
Xaml
<Style x:Key="GridViewColumnHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="ToolTip" Value="{Binding Path=Column.(attachedProperties:GridViewColumnHeaderToolTipAttachedProperty.Tooltip), RelativeSource={RelativeSource Self}}" />
</Style>
<GridView x:Key="GridViewFuelConsumption"
x:Shared="False">
<GridViewColumn Header="Ред.Број"
DisplayMemberBinding="{Binding RedenBroj}"
HeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle}"
attachedProperties:GridViewColumnHeaderToolTipAttachedProperty.Tooltip="Your explanation" />
</GridView>
AttachedProperty
public sealed class GridViewColumnHeaderToolTipAttachedProperty : DependencyObject
{
public static readonly DependencyProperty TooltipSourceProperty = DependencyProperty.RegisterAttached(
"Tooltip",
typeof(string),
typeof(GridViewColumnHeaderToolTipAttachedProperty),
new PropertyMetadata("null"));
public static void SetTooltip(DependencyObject element, string value)
{
element.SetValue(TooltipSourceProperty, value);
}
public static string GetTooltip(DependencyObject element)
{
return (string)element.GetValue(TooltipSourceProperty);
}
}