Andrew Simpson
Andrew Simpson

Reputation: 7324

How to add a tooltip to a datagrid cell

i have a wpf c# app.

I am using the datagrid control.

for one of these cells I want to show a mutli-line tool-tip.

this is my code:

<DataGridTextColumn Header="{x:Static prop:Resources.Address}" Binding="{Binding Address}" >
    <ToolTipService.ToolTip>
        <StackPanel>
            <TextBlock Text="Line#1" />
            <TextBlock Text="Line#2" />
        </StackPanel>
    </ToolTipService.ToolTip>
</DataGridTextColumn>

But when I run this no tool-tip is displayed?

Upvotes: 2

Views: 3523

Answers (1)

mm8
mm8

Reputation: 169200

You could set the Tooltip property of the DataGridCell using a CellStyle:

<DataGridTextColumn Header="{x:Static prop:Resources.Address}" Binding="{Binding Address}" >
    <DataGridTextColumn.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="ToolTip">
                <Setter.Value>
                    <ToolTip>
                        <StackPanel>
                            <TextBlock Text="Line#1" />
                            <TextBlock Text="Line#2" />
                        </StackPanel>
                    </ToolTip>
                </Setter.Value>
            </Setter>
        </Style>
    </DataGridTextColumn.CellStyle>
</DataGridTextColumn>

Upvotes: 9

Related Questions