Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/docs/column-sizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ Disable resizing for a specific column:

Prefer `Preview` if users report a slow or stuttery resize drag on grids with many visible rows; keep the default `Live` if you need cells to reflect the in-progress width at every instant (for example, a template column that reacts to its own width while dragging).

### Star columns while the window resizes

Star (`*`) columns take the width the other columns leave, so every change in the TableView's width recalculates them, and every realized cell in a star column lays out again. While the user drags the window edge that happens on every frame, which can make resizing stutter on wide or text-heavy tables. [`StarColumnResizeDelay`](xref:WinUI.TableView.TableView.StarColumnResizeDelay) makes star columns wait until the width has stopped changing for that long:

```xml
<tv:TableView StarColumnResizeDelay="0:0:0.12" />
```

During the drag, star columns keep their previous width (the table may briefly show a gap or a horizontal scroll bar), then catch up. The first layout and fixed-width columns don't wait. The default, zero, recalculates on every change.

## Row and header row heights

Control row heights with the following `TableView` properties:
Expand Down
17 changes: 17 additions & 0 deletions src/TableView.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ public partial class TableView
/// </summary>
public static readonly DependencyProperty ShowFilterItemsCountProperty = DependencyProperty.Register(nameof(ShowFilterItemsCount), typeof(bool), typeof(TableView), new PropertyMetadata(false));

/// <summary>
/// Identifies the <see cref="StarColumnResizeDelay"/> dependency property.
/// </summary>
public static readonly DependencyProperty StarColumnResizeDelayProperty = DependencyProperty.Register(nameof(StarColumnResizeDelay), typeof(TimeSpan), typeof(TableView), new PropertyMetadata(TimeSpan.Zero));


/// <summary>
/// Identifies the <see cref="ForceRowOrCellSelectionOnContextRequested"/> dependency property.
Expand Down Expand Up @@ -412,6 +417,18 @@ public bool ShowFilterItemsCount
set => SetValue(ShowFilterItemsCountProperty, value);
}

/// <summary>
/// Gets or sets how long star-sized columns wait, after the TableView's width stops changing, before they take up
/// the new width. While the window is being resized, recalculating them on every frame re-lays out every realized
/// cell in those columns, which makes resizing stutter on wide or text-heavy tables. Zero (the default) recalculates
/// on every change.
/// </summary>
public TimeSpan StarColumnResizeDelay
{
get => (TimeSpan)GetValue(StarColumnResizeDelayProperty);
set => SetValue(StarColumnResizeDelayProperty, value);
}

/// <summary>
/// Gets or sets a value indicating whether the drag selection rectangle is shown during cell drag selection.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions src/TableViewHeaderRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public partial class TableViewHeaderRow : Control
private TranslateTransform? _columnDropIndicatorTransform;
private Image? _dragHeaderImage;
private DispatcherTimer? _desiredWidthTimer;
private DispatcherTimer? _starResizeTimer;
private bool _calculatingHeaderWidths;
private int _dropColumnIndex;
private bool _isValidDropTarget;
Expand Down Expand Up @@ -760,6 +761,25 @@ public void ClearHeaders()
/// </summary>
private void OnTableViewSizeChanged(object sender, SizeChangedEventArgs e)
{
// Resizing a star column re-lays out every realized cell in it, on every frame of a window resize. With a
// delay set, star widths catch up once the resize pauses; the first layout and fixed-width columns don't wait.
if (TableView is { StarColumnResizeDelay: { } delay } && delay > TimeSpan.Zero && e.PreviousSize.Width > 0)
{
_starResizeTimer ??= new DispatcherTimer();
_starResizeTimer.Interval = delay;
_starResizeTimer.Tick -= OnStarResizeTimerTick;
_starResizeTimer.Tick += OnStarResizeTimerTick;
_starResizeTimer.Stop();
_starResizeTimer.Start();
return;
}

CalculateHeaderWidths();
}

private void OnStarResizeTimerTick(object? sender, object e)
{
_starResizeTimer?.Stop();
CalculateHeaderWidths();
}

Expand Down