Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add tooltip text on my Gridview column header, WPF VS2010

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>
like image 851
denza Avatar asked Jun 22 '12 11:06

denza


2 Answers

You could do this:

<GridViewColumn Width="50"
                DisplayMemberBinding="{Binding Path=RedenBroj}">
    <GridViewColumn.Header>
        <TextBlock Text="Ред.Број"
                   ToolTip="Your explanation" />                      
    </GridViewColumn.Header>        
</GridViewColumn>
like image 55
LPL Avatar answered Nov 10 '22 03:11

LPL


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>
like image 24
Scroog1 Avatar answered Nov 10 '22 03:11

Scroog1