Drahcir
Drahcir

Reputation: 11972

Add custom tooltip to row in DataGrid

I would like to customize my DataGrid to show a tooltip within the selected row, please see the mockup images below for a better idea of what I want to achieve.

As it is at the moment - Shows a single selected row: enter image description here

How I would like - Shows the same row selected, now with tooltip:

enter image description here

I don't really have any idea how to achieve this, so I'm open to any suggestions at all.

Upvotes: 13

Views: 21083

Answers (3)

FlyingOliver
FlyingOliver

Reputation: 21

Another simple way to add a tooltip on a row in a datagrid is the following.

Use the LodingRowEvent and add your tooltip like this:

private void grdItemlogs_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        if (e.Row != null)
        {
            string toolTipText = "Your Tooltip string content"
            e.Row.ToolTip = toolTipText;

        }
    }

Upvotes: 2

kmatyaszek
kmatyaszek

Reputation: 19296

You can use RowDetailsTemplate.

Here is sample code:

<DataGrid Name="grid" AutoGenerateColumns="False">
    <DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <TextBlock Background="Orange" Text="{Binding MoreInfo}" TextWrapping="Wrap"
                       HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        </DataTemplate>
    </DataGrid.RowDetailsTemplate>
    <DataGrid.Columns>
        <DataGridTextColumn Header="ID" Binding="{Binding ID}" />
        <DataGridTextColumn Header="ID" Binding="{Binding Name}" />
        <DataGridTextColumn Header="ID" Binding="{Binding Surname}" />
    </DataGrid.Columns>
</DataGrid>

Upvotes: 17

Martin
Martin

Reputation: 5623

I use the DataGrid.RowStyle to set the tooltip.

My bound objects have a ToolTipText property which contains the content of the ToolTip.

<DataGrid.RowStyle>
    <Style TargetType="DataGridRow">
        <Setter Property="ToolTip">
            <Setter.Value>
                <TextBlock Text="{Binding ToolTipText}" />
            </Setter.Value>
        </Setter>
    </Style>
</DataGrid.RowStyle>

Upvotes: 29

Related Questions