Skip to content

Commit 888d8d2

Browse files
committed
Merge 'origin/main' into 'perf/optimize_sort_filter_ops'
2 parents a71bfb5 + e068319 commit 888d8d2

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/Columns/TableViewColumn.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,20 @@ private static void OnHeaderStyleChanged(DependencyObject d, DependencyPropertyC
455455
}
456456
}
457457

458+
/// <summary>
459+
/// Gets or sets the member path to use for sorting instead of the default binding path.
460+
/// </summary>
461+
public string? SortMemberPath
462+
{
463+
get => (string?)GetValue(SortMemberPathProperty);
464+
set => SetValue(SortMemberPathProperty, value);
465+
}
466+
467+
/// <summary>
468+
/// Identifies the SortMemberPath dependency property.
469+
/// </summary>
470+
public static readonly DependencyProperty SortMemberPathProperty = DependencyProperty.Register(nameof(SortMemberPath), typeof(string), typeof(TableViewColumn), new PropertyMetadata(null));
471+
458472
/// <summary>
459473
/// Identifies the HeaderStyle dependency property.
460474
/// </summary>

src/ItemsSource/ColumnSortDescription.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public ColumnSortDescription(TableViewColumn column,
2121

2222
public override object? GetPropertyValue(object? item)
2323
{
24+
// Use reflection-based property access when SortMemberPath is explicitly provided; otherwise, fall back to column cell content.
25+
if (!string.IsNullOrEmpty(PropertyName))
26+
{
27+
return base.GetPropertyValue(item);
28+
}
2429
return Column.GetCellContent(item);
2530
}
2631

src/TableView.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public TableView()
5656
RegisterPropertyChangedCallback(ListViewBase.SelectionModeProperty, OnBaseSelectionModeChanged);
5757

5858
Loaded += OnLoaded;
59+
Unloaded += OnUnloaded;
5960
SelectionChanged += TableView_SelectionChanged;
6061
_collectionView.ItemPropertyChanged += OnItemPropertyChanged;
6162
}
@@ -319,6 +320,17 @@ private void OnLoaded(object sender, RoutedEventArgs e)
319320
EnsureAutoColumns();
320321
}
321322

323+
/// <summary>
324+
/// Handles the Unloaded event of the TableView control.
325+
/// </summary>
326+
private void OnUnloaded(object sender, RoutedEventArgs e)
327+
{
328+
if (IsEditing && CurrentCellSlot.HasValue && GetCellFromSlot(CurrentCellSlot.Value) is { } currentCell)
329+
{
330+
currentCell.EndEditing(TableViewEditAction.Commit);
331+
}
332+
}
333+
322334
/// <summary>
323335
/// Handles the PointerWheelChanged event of the ScrollContentPresenter.
324336
/// </summary>

src/TableViewColumnHeader.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ private void DoSort(SD? direction, bool singleSorting = true)
112112
{
113113
var boundColumn = Column as TableViewBoundColumn;
114114
Column.SortDirection = direction;
115+
116+
// Prefer explicit SortMemberPath if provided, otherwise use bound column's property path
117+
var sortPath = Column.SortMemberPath ?? boundColumn?.PropertyPath;
118+
115119
_tableView.SortDescriptions.Add(
116-
new ColumnSortDescription(Column!, boundColumn?.PropertyPath, direction.Value));
120+
new ColumnSortDescription(Column!, sortPath, direction.Value));
117121
}
118122
}
119123
}

0 commit comments

Comments
 (0)