Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGridTextColumn should support text trimming (with tooltip) #10554

Open
Patch4747 opened this issue Mar 11, 2025 · 3 comments
Open

DataGridTextColumn should support text trimming (with tooltip) #10554

Patch4747 opened this issue Mar 11, 2025 · 3 comments
Labels
Enhancement Requested Product code improvement that does NOT require public API changes/additions

Comments

@Patch4747
Copy link

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"/>
@Patch4747
Copy link
Author

Screenshot from Task Manager demonstrating proposed behavior:

Image

@himgoyalmicro himgoyalmicro added Enhancement Requested Product code improvement that does NOT require public API changes/additions and removed Untriaged labels Mar 12, 2025
@Symbai
Copy link
Contributor

Symbai commented Mar 12, 2025

If trimmed it should display the tooltip automatically. I dont think we need a separate option for that. If for some reasons a dev does not want this behavior then he can simply override it.

@miloush
Copy link
Contributor

miloush commented Mar 12, 2025

It depends on the application scenario (Excel for example doesn't do that) and trimming has non-trivial performance impact, so I would be cautious with a default behavior.

Also note that there isn't an easily accessible way to find out whether a TextBlock is trimmed or not, but it would be useful to add that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Requested Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

4 participants