9

Here is my grid i what to give an explanation to the header "RED.BROJ" when on mouse over that header to show the expl. text.

<ListView.View>
    <GridView>
        <GridViewColumn Width="50"
                        Header="Реd.Број"
                        DisplayMemberBinding="{Binding Path=RedenBroj}">
        </GridViewColumn>

3 Answers 3

12

You could do this:

<GridViewColumn Width="50"
                DisplayMemberBinding="{Binding Path=RedenBroj}">
    <GridViewColumn.Header>
        <TextBlock Text="Ред.Број"
                   ToolTip="Your explanation" />                      
    </GridViewColumn.Header>        
</GridViewColumn>
Sign up to request clarification or add additional context in comments.

Comments

11

Slightly late response but you can add a tooltip, without losing the ability to drag columns to reorder them, by doing the following:

<GridViewColumn Width="50"
                Header="Реd.Број"
                DisplayMemberBinding="{Binding Path=RedenBroj}">
    <GridViewColumn.HeaderContainerStyle>
        <Style>
            <Setter Property="Control.ToolTip" Value="Tool tip content"/>
        </Style>
    </GridViewColumn.HeaderContainerStyle>
</GridViewColumn>

Update: more concise version thanks to LPL

Further update: I wanted to be able to have all columns have tooltips that match their headers (as some columns were too narrow to show the whole header):

<ListView.View>
    <GridView>
        <GridView.ColumnHeaderContainerStyle>
            <Style TargetType="GridViewColumnHeader">
                <Setter Property="ToolTip"
                        Value="{Binding Content, RelativeSource={RelativeSource Self}}"/>
            </Style>
        </GridView.ColumnHeaderContainerStyle>

        <GridViewColumn DisplayMemberBinding="{Binding A}" Header="A"/>
        <GridViewColumn DisplayMemberBinding="{Binding B}" Header="B"/>
        <GridViewColumn DisplayMemberBinding="{Binding C}" Header="C"/>
    </GridView>
</ListView>

2 Comments

I think it could be a little bit less verbose (<GridViewColumn.HeaderContainerStyle><Style><Setter Property="Control.ToolTip" Value="Tool tip content" /></Style></GridViewColumn.HeaderContainerStyle>) but better solution than mine. +1
How could I use another value from the GridViewColumn to display a different ToolTip than the content already visible in the header? I tried it with the "Tag" property but although I could use "Tag" as binding in the setter value, I can't assign a "Tag" property to the GridViewColumn like this: <GridViewColumn Header="A" Tag="ToolTip-Content" />
0

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);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.