Skip to main content

Microsoft Silverlight

Answered Question Datagrid Header TooltipRSS Feed

(0)

Zachary D.
Zachary D.

Member

Member

77 points

187 Posts

Datagrid Header Tooltip

What is the best way to add a tooltip to a datagrid header in SL 3?

The tooltips need to be dynamic

TomBeeby
TomBeeby

Participant

Participant

1151 points

188 Posts

Answered Question

Re: Datagrid Header Tooltip

To start with, do something 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>
</data:DataGrid>

  

You'll need to add this namespace declaration too

 

xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"

  

As far making it dynamic, i'm not sure what you mean by that.. you could bind the text of the tooltip to some value, or even handle the opened event of the Tooltip, grab the tooltip's data context and then based on that decide what to put in the tooltip.

 

Zachary D.
Zachary D.

Member

Member

77 points

187 Posts

Re: Datagrid Header Tooltip

 The problem I am running into here is that this takes away the abilty to sort the datagrid when the column is clicked on

Zachary D.
Zachary D.

Member

Member

77 points

187 Posts

Re: Datagrid Header Tooltip

 actually sorting does still work... thanks for the help

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities