Add ColumnAutoWidthMode#361
Conversation
|
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. |
|
I think if you add a condition for ColumnAutoWidthMode in |
w-ahmad
left a comment
There was a problem hiding this comment.
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.
|
I've added a sample page, and when playing around with it I've come to the conclusion that there's definately more to it to get it to work when changing the values in runtime. Will have to dig further when I have more time. |
|
hey @Mangepange, let me know if you need any help implementing this feature! I’m aiming for a v1.5 preview release soon, and the PR can be included in it. |
|
Unfortunately I haven't had the time to investigate this further. Feel free to have a look if you want to! |
There was a problem hiding this comment.
Pull request overview
This PR introduces a new auto-sizing policy (TableViewColumnAutoWidthMode) to control whether auto column width calculations consider cell content, header content, or both—addressing issue #358 (“Include header in column width”) and aligning the double-tap resize behavior with the new policy.
Changes:
- Added
ColumnAutoWidthModeonTableView(global default) andTableViewColumn(per-column override). - Updated header/cell measuring and the double-tap “auto size” behavior to use
GridLength.Autoand the new mode. - Added a new SampleApp page to demonstrate the feature.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/TableViewHeaderRow.cs | Centralizes desired-width calculation and (optionally) includes header width in auto sizing. |
| src/TableViewColumnHeader.cs | Changes double-tap sizing to set Width=Auto and updates measuring to feed header desired width into sizing. |
| src/TableViewColumnAutoWidthMode.cs | Adds the new public enum defining auto sizing modes. |
| src/TableViewCell.cs | Updates cell measurement to contribute to desired width only when mode includes cells. |
| src/TableView.Properties.cs | Adds the TableView.ColumnAutoWidthMode dependency property and triggers recalculation on change. |
| src/TableView.cs | Adds RefreshColumnsAutoWidth helper to reset/recompute desired widths. |
| src/Columns/TableViewColumn.cs | Adds per-column ColumnAutoWidthMode dependency property and triggers recalculation on change. |
| samples/WinUI.TableView.SampleApp/Pages/ColumnSizingPage.xaml(.cs) | New sample page demonstrating column auto width mode selection. |
| samples/WinUI.TableView.SampleApp/MainPage.xaml.cs | Adds navigation mapping for the new “Column Sizing” sample page. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.