Skip to content

DataGridTextColumn should support text trimming (with tooltip) #10554

@Patch4747

Description

@Patch4747

DataGridTextColumn should have an attribute that enables text trimming and provides a dynamic tooltip. Example:

<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding People}">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
        <DataGridTextColumn Header="Address" Binding="{Binding Address}" TrimAndProvideTooltip="True"/>
    </DataGrid.Columns>
</DataGrid>

Motivation

This behavior is ubiquitous in grid-like UI elements throughout Windows OS and other software. Text trimming is a strong UX feature; it communicates to the user that they are not viewing the entire block of text. A tooltip makes it easy to see that full text without adjusting the UI control, which may be difficult or impossible if resizing is disabled.

Many Windows programs have this proposed behavior. Examples in Windows 10 are File Explorer (details view) and Task Manager (Details or Services tab).

There are ways to implement this currently, but neither are very robust. Because DataGridTextColumn does not derive from FrameworkElement, it is not possible to use a style. Could use a DataGridTemplateColumn, but then you have the challenge of recreating the text template that DataGridTextColumn already provides.

Implementation details

These details are based on my experience with the proposed behavior.

  • The text trimming employed is CharacterEllipsis, as defined by TextTrimming.CharacterEllipsis.
  • The tooltip is enabled only when the text is trimmed.
  • The tooltip has a very quick initial show delay.

Alternatives

  • Separate text trimming and tooltip behavior:
<DataGridTextColumn Header="Address" Binding="{Binding Address}" TextTrimming="CharacterEllipsis" ShowTooltipIfTrimmed="True"/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement RequestedProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions