@@ -75,7 +75,7 @@ private void TableView_SelectionChanged(object sender, SelectionChangedEventArgs
75
75
} ) ;
76
76
}
77
77
78
- SetCurrentCell ( null ) ;
78
+ CurrentCellSlot = null ;
79
79
OnCellSelectionChanged ( ) ;
80
80
81
81
if ( SelectedIndex > 0 )
@@ -192,7 +192,7 @@ private void HandleNavigations(KeyRoutedEventArgs e, bool shiftKey, bool ctrlKey
192
192
if ( isEditing && currentCell is not null )
193
193
{
194
194
currentCell = GetCellFromSlot ( newSlot ) ;
195
- currentCell . PrepareForEdit ( ) ;
195
+ currentCell ? . PrepareForEdit ( ) ;
196
196
}
197
197
198
198
e . Handled = true ;
@@ -803,7 +803,7 @@ public void RefreshFilter()
803
803
if ( SelectionUnit is TableViewSelectionUnit . Cell )
804
804
{
805
805
SelectAllCells ( ) ;
806
- SetCurrentCell ( null ) ;
806
+ CurrentCellSlot = null ;
807
807
}
808
808
else
809
809
{
@@ -886,7 +886,7 @@ private void DeselectAllCells()
886
886
{
887
887
SelectedCellRanges . Clear ( ) ;
888
888
OnCellSelectionChanged ( ) ;
889
- SetCurrentCell ( null ) ;
889
+ CurrentCellSlot = null ;
890
890
}
891
891
892
892
/// <summary>
@@ -922,17 +922,17 @@ internal void MakeSelection(TableViewCellSlot slot, bool shiftKey, bool ctrlKey
922
922
{
923
923
SelectRows ( slot , shiftKey ) ;
924
924
LastSelectionUnit = TableViewSelectionUnit . Row ;
925
- }
926
- else
927
- {
925
+ }
926
+ else
927
+ {
928
928
SelectCells ( slot , shiftKey ) ;
929
929
LastSelectionUnit = TableViewSelectionUnit . Cell ;
930
930
}
931
931
}
932
932
else if ( ! IsReadOnly )
933
933
{
934
934
SelectionStartCellSlot = slot ;
935
- DispatcherQueue . TryEnqueue ( ( ) => SetCurrentCell ( slot ) ) ;
935
+ CurrentCellSlot = slot ;
936
936
}
937
937
}
938
938
@@ -948,14 +948,14 @@ private void SelectRows(TableViewCellSlot slot, bool shiftKey)
948
948
if ( selectionRange is not null )
949
949
{
950
950
DeselectRange ( selectionRange ) ;
951
- }
951
+ }
952
952
953
953
if ( shiftKey && SelectionMode is ListViewSelectionMode . Multiple or ListViewSelectionMode . Extended )
954
954
{
955
955
var min = Math . Min ( SelectionStartRowIndex . Value , slot . Row ) ;
956
956
var max = Math . Max ( SelectionStartRowIndex . Value , slot . Row ) ;
957
957
958
- SelectRange ( new ItemIndexRange ( min , ( uint ) ( max - min ) + 1 ) ) ;
958
+ SelectRange ( new ItemIndexRange ( min , ( uint ) ( max - min ) + 1 ) ) ;
959
959
}
960
960
else
961
961
{
@@ -968,11 +968,11 @@ private void SelectRows(TableViewCellSlot slot, bool shiftKey)
968
968
{
969
969
SelectRange ( new ItemIndexRange ( slot . Row , 1 ) ) ;
970
970
}
971
- }
971
+ }
972
972
973
973
if ( ! IsReadOnly && slot . IsValid ( this ) )
974
974
{
975
- DispatcherQueue . TryEnqueue ( ( ) => SetCurrentCell ( slot ) ) ;
975
+ CurrentCellSlot = slot ;
976
976
}
977
977
else
978
978
{
@@ -1033,7 +1033,7 @@ private void SelectCells(TableViewCellSlot slot, bool shiftKey)
1033
1033
1034
1034
SelectedCellRanges . Add ( selectionRange ) ;
1035
1035
OnCellSelectionChanged ( ) ;
1036
- DispatcherQueue . TryEnqueue ( ( ) => SetCurrentCell ( slot ) ) ;
1036
+ CurrentCellSlot = slot ;
1037
1037
}
1038
1038
1039
1039
/// <summary>
@@ -1049,38 +1049,32 @@ internal void DeselectCell(TableViewCellSlot slot)
1049
1049
SelectedCellRanges . Remove ( selectionRange ) ;
1050
1050
}
1051
1051
1052
- SetCurrentCell ( slot ) ;
1052
+ CurrentCellSlot = slot ;
1053
1053
OnCellSelectionChanged ( ) ;
1054
1054
}
1055
1055
1056
1056
/// <summary>
1057
- /// Sets the current cell based on the specified cell slot .
1057
+ /// Handles changes to the current cell in the table view .
1058
1058
/// </summary>
1059
- internal async void SetCurrentCell ( TableViewCellSlot ? slot )
1059
+ private async Task OnCurrentCellChanged ( TableViewCellSlot ? oldSlot , TableViewCellSlot ? newSlot )
1060
1060
{
1061
- if ( slot == CurrentCellSlot )
1061
+ if ( oldSlot == newSlot )
1062
1062
{
1063
1063
return ;
1064
1064
}
1065
1065
1066
- var oldSlot = CurrentCellSlot ;
1067
- var currentCell = oldSlot . HasValue ? GetCellFromSlot ( oldSlot . Value ) : default ;
1068
- currentCell ? . SetElement ( ) ;
1069
- CurrentCellSlot = slot ;
1070
-
1071
- if ( oldSlot is { } )
1066
+ if ( oldSlot . HasValue )
1072
1067
{
1073
- var row = _rows . FirstOrDefault ( x => x . Index == oldSlot . Value . Row ) ;
1074
- row ? . ApplyCurrentCellState ( oldSlot . Value ) ;
1068
+ var cell = GetCellFromSlot ( oldSlot . Value ) ;
1069
+ cell ? . SetElement ( ) ;
1070
+ cell ? . ApplyCurrentCellState ( ) ;
1075
1071
}
1076
1072
1077
- if ( slot is { } )
1073
+ if ( newSlot . HasValue )
1078
1074
{
1079
- var cell = await ScrollCellIntoView ( slot . Value ) ;
1075
+ var cell = await ScrollCellIntoView ( newSlot . Value ) ;
1080
1076
cell ? . ApplyCurrentCellState ( ) ;
1081
1077
}
1082
-
1083
- CurrentCellChanged ? . Invoke ( this , new TableViewCurrentCellChangedEventArgs ( oldSlot , slot ) ) ;
1084
1078
}
1085
1079
1086
1080
/// <summary>
@@ -1241,9 +1235,9 @@ void ViewChanged(object? _, ScrollViewerViewChangedEventArgs e)
1241
1235
/// <summary>
1242
1236
/// Gets the cell based on the specified cell slot.
1243
1237
/// </summary>
1244
- internal TableViewCell GetCellFromSlot ( TableViewCellSlot slot )
1238
+ internal TableViewCell ? GetCellFromSlot ( TableViewCellSlot slot )
1245
1239
{
1246
- return slot . IsValid ( this ) && ContainerFromIndex ( slot . Row ) is TableViewRow row ? row . Cells [ slot . Column ] : default ! ;
1240
+ return slot . IsValid ( this ) && ContainerFromIndex ( slot . Row ) is TableViewRow row ? row . Cells [ slot . Column ] : default ;
1247
1241
}
1248
1242
1249
1243
/// <summary>
@@ -1494,7 +1488,7 @@ public virtual void OnClearSorting(TableViewClearSortingEventArgs eventArgs)
1494
1488
public event EventHandler < TableViewCellSelectionChangedEventArgs > ? CellSelectionChanged ;
1495
1489
1496
1490
/// <summary>
1497
- /// Internal event triggered when the current cell changes.
1491
+ /// Event triggered when the current cell changes.
1498
1492
/// </summary>
1499
- internal event EventHandler < TableViewCurrentCellChangedEventArgs > ? CurrentCellChanged ;
1493
+ public event DependencyPropertyChangedEventHandler ? CurrentCellChanged ;
1500
1494
}
0 commit comments