Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/TableView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@
/// </summary>
private void OnLoaded(object sender, RoutedEventArgs e)
{
if (_isItemsSourceSuspended) // indicates that the control was unloaded and loaded back
{
_headerRow?.CalculateHeaderWidths(); // Needed when switching back to an existing TableView (without provided column Widths)
}

ResumeItemsSource();
EnsureAutoColumns();
}
Expand Down Expand Up @@ -731,7 +736,7 @@
}
else
{
foreach (var propertyInfo in dataType.GetProperties())

Check warning on line 739 in src/TableView.cs

View workflow job for this annotation

GitHub Actions / build (ARM64)

'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The return value of method 'WinUI.TableView.Extensions.ObjectExtensions.GetItemType(IEnumerable)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Check warning on line 739 in src/TableView.cs

View workflow job for this annotation

GitHub Actions / build

'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The return value of method 'WinUI.TableView.Extensions.ObjectExtensions.GetItemType(IEnumerable)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
{
var displayAttribute = propertyInfo.GetCustomAttributes().OfType<DisplayAttribute>().FirstOrDefault();
var autoGenerateField = displayAttribute?.GetAutoGenerateField();
Expand Down
23 changes: 23 additions & 0 deletions src/TableViewHeaderRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public partial class TableViewHeaderRow : Control
private Border? _columnDropIndicator;
private TranslateTransform? _columnDropIndicatorTransform;
private Image? _dragHeaderImage;
private DispatcherTimer? _desiredWidthTimer;
private bool _calculatingHeaderWidths;
private int _dropColumnIndex;
private bool _isValidDropTarget;
Expand Down Expand Up @@ -201,6 +202,28 @@ e.PropertyName is nameof(TableViewColumn.IsFrozen)) &&
CalculateHeaderWidths();
}
}
else if (e.PropertyName is nameof(TableViewColumn.DesiredWidth))
{
// Coalesce multiple updates (see in-loop Measure() call in CalculateHeaderWidths) to avoid excessive header width calculations.
_desiredWidthTimer ??= new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(250) };
_desiredWidthTimer.Tick -= OnDesiredWidthTimerTick;
_desiredWidthTimer.Tick += OnDesiredWidthTimerTick;
_desiredWidthTimer.Stop();
_desiredWidthTimer.Start();
}
}

/// <summary>
/// Recalculates header widths after deferred desired-width updates.
/// </summary>
private void OnDesiredWidthTimerTick(object? sender, object e)
{
_desiredWidthTimer?.Stop();

if (!_calculatingHeaderWidths)
{
CalculateHeaderWidths();
}
}

/// <summary>
Expand Down
Loading