Skip to content

Commit 10ff33a

Browse files
committed
Exposed CellSelectionChanged evnet
1 parent 163ce18 commit 10ff33a

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/EventArgs/TableViewCellSelectionChangedEvenArgs.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ namespace WinUI.TableView;
66
/// <summary>
77
/// Provides data for the cell selection changed event.
88
/// </summary>
9-
internal class TableViewCellSelectionChangedEvenArgs : EventArgs
9+
public class TableViewCellSelectionChangedEventArgs : EventArgs
1010
{
1111
/// <summary>
12-
/// Initializes a new instance of the TableViewCellSelectionChangedEvenArgs class.
12+
/// Initializes a new instance of the TableViewCellSelectionChangedEventArgs class.
1313
/// </summary>
14-
/// <param name="oldSelection">The old selection of cells.</param>
15-
/// <param name="newSelection">The new selection of cells.</param>
16-
public TableViewCellSelectionChangedEvenArgs(HashSet<TableViewCellSlot> oldSelection,
17-
HashSet<TableViewCellSlot> newSelection)
14+
/// <param name="removedCells">The list that contains the cells that were unselected.</param>
15+
/// <param name="addedCells">The list that contains the cells that were selected.</param>
16+
public TableViewCellSelectionChangedEventArgs(IList<TableViewCellSlot> removedCells,
17+
IList<TableViewCellSlot> addedCells)
1818
{
19-
OldSelection = oldSelection;
20-
NewSelection = newSelection;
19+
RemovedCells = removedCells;
20+
AddedCells = addedCells;
2121
}
2222

2323
/// <summary>
24-
/// Gets the old selection of cells.
24+
/// Gets a list that contains the cells that were unselected.
2525
/// </summary>
26-
public HashSet<TableViewCellSlot> OldSelection { get; }
26+
public IList<TableViewCellSlot> RemovedCells { get; }
2727

2828
/// <summary>
29-
/// Gets the new selection of cells.
29+
/// Gets a list that contains the cells that were selected.
3030
/// </summary>
31-
public HashSet<TableViewCellSlot> NewSelection { get; }
31+
public IList<TableViewCellSlot> AddedCells { get; }
3232
}

src/TableView.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,24 @@ private void OnCellSelectionChanged()
11011101
row?.ApplyCellsSelectionState();
11021102
}
11031103

1104-
SelectedCellsChanged?.Invoke(this, new TableViewCellSelectionChangedEvenArgs(oldSelection, SelectedCells));
1104+
InvokeCellSelectionChangedEvent(oldSelection);
11051105
});
11061106
}
11071107

1108+
/// <summary>
1109+
/// Invokes the <see cref="CellSelectionChanged"/> event to notify subscribers of changes in the selected cells.
1110+
/// </summary>
1111+
private void InvokeCellSelectionChangedEvent(HashSet<TableViewCellSlot> oldSelection)
1112+
{
1113+
var removedCells = oldSelection.Except(SelectedCells).ToList();
1114+
var addedCells = SelectedCells.Except(oldSelection).ToList();
1115+
1116+
if (removedCells.Count > 0 || addedCells.Count > 0)
1117+
{
1118+
CellSelectionChanged?.Invoke(this, new TableViewCellSelectionChangedEventArgs(removedCells, addedCells));
1119+
}
1120+
}
1121+
11081122
/// <summary>
11091123
/// Scrolls the specified cell slot into view.
11101124
/// </summary>
@@ -1475,9 +1489,9 @@ public virtual void OnClearSorting(TableViewClearSortingEventArgs eventArgs)
14751489
public event EventHandler<TableViewClearSortingEventArgs>? ClearSorting;
14761490

14771491
/// <summary>
1478-
/// Internal event triggered when selected cells change.
1492+
/// Event triggered when selected cells change.
14791493
/// </summary>
1480-
internal event EventHandler<TableViewCellSelectionChangedEvenArgs>? SelectedCellsChanged;
1494+
public event EventHandler<TableViewCellSelectionChangedEventArgs>? CellSelectionChanged;
14811495

14821496
/// <summary>
14831497
/// Internal event triggered when the current cell changes.

0 commit comments

Comments
 (0)