Skip to content

Add ColumnAutoWidthMode#361

Open
Mangepange wants to merge 4 commits into
w-ahmad:mainfrom
Mangepange:feature_358_autosizing
Open

Add ColumnAutoWidthMode#361
Mangepange wants to merge 4 commits into
w-ahmad:mainfrom
Mangepange:feature_358_autosizing

Conversation

@Mangepange
Copy link
Copy Markdown

This is a suggestion for how to solve #358.

I added a new property to TableView and TableViewCell. The property sets a ColumnAutoWidthMode which describes how the column should calculate its width when sizing to its content (doubleclicking on the column separator, or when no startup size is set).

It's sort of the same as the functionality in DataGrid, https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/sizing-options-in-the-datagrid-control#sizing-columns-and-column-headers, but not including "Pixel" or "Star" modes. I think that those two modes are better defined when the user sets the actual Width value.

I'm a bit unsure how to test regarding the fix for WinUI issue 9860 in TableViewCell.MeasureOverride.

Copy link
Copy Markdown
Owner

@w-ahmad w-ahmad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TableView currently includes the header width when calculating column sizes at startup, see the header row line 295. With this new feature, we need to ensure it only applies depending on the property.

Comment thread src/Columns/TableViewColumn.cs
@Mangepange
Copy link
Copy Markdown
Author

Do you have any thought on how a column should behave when there's no rows and the ColumnAutoWidthMode is set to Cells? It's currently sized to the header. I'm using the sample application, and even if the rows are added early, the column widths are calculated earlier, and this makes it difficult to solve ColumnAutoWidthMode.Cells during the first size pass.

@w-ahmad
Copy link
Copy Markdown
Owner

w-ahmad commented May 19, 2026

I think if you add a condition for ColumnAutoWidthMode in TableViewHeaderRow.CalculateHeaderWidths at line 292, you should be good. If you still think there might be other scenarios where it won’t work, just ping me on Discord and we can have a quick chat.

@Mangepange Mangepange requested a review from w-ahmad May 19, 2026 18:09
Copy link
Copy Markdown
Owner

@w-ahmad w-ahmad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates @Mangepange, I tried these changes and they work fine, except when the property is changed at runtime using XAML HotReload. We need to ensure that the TableView responds to property changes during runtime.
Also, please add a sample page to demonstrate this new change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants