From 8ca5d0ed736303abb91fdbfb4494428b49196191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Torsg=C3=A5rden?= Date: Tue, 28 Apr 2026 16:12:03 +0200 Subject: [PATCH 1/3] End editing on PointerPress --- src/TableView.cs | 16 ++++++++-------- src/TableViewCell.cs | 39 +++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/TableView.cs b/src/TableView.cs index e21a6d3e..820ee410 100644 --- a/src/TableView.cs +++ b/src/TableView.cs @@ -133,7 +133,7 @@ protected override DependencyObject GetContainerForItemOverride() } /// - protected override async void OnKeyDown(KeyRoutedEventArgs e) + protected override void OnKeyDown(KeyRoutedEventArgs e) { var shiftKey = KeyboardHelper.IsShiftKeyDown(); var ctrlKey = KeyboardHelper.IsCtrlKeyDown(); @@ -144,19 +144,19 @@ protected override async void OnKeyDown(KeyRoutedEventArgs e) return; } - await HandleNavigations(e, shiftKey, ctrlKey); + HandleNavigations(e, shiftKey, ctrlKey); } /// /// Handles navigation keys. /// - private async Task HandleNavigations(KeyRoutedEventArgs e, bool shiftKey, bool ctrlKey) + private void HandleNavigations(KeyRoutedEventArgs e, bool shiftKey, bool ctrlKey) { var currentCell = CurrentCellSlot.HasValue ? GetCellFromSlot(CurrentCellSlot.Value) : default; if (e.Key is VirtualKey.F2 && currentCell is { IsReadOnly: false } && !IsEditing) { - e.Handled = await currentCell.BeginCellEditing(e); + e.Handled = currentCell.BeginCellEditing(e); } else if (e.Key is VirtualKey.Escape && currentCell is not null && IsEditing) { @@ -192,7 +192,7 @@ private async Task HandleNavigations(KeyRoutedEventArgs e, bool shiftKey, bool c { if (!EndCellEditing(TableViewEditAction.Commit, currentCell)) return; - if (CurrentCellSlot == newSlot || GetCellFromSlot(newSlot) is not { } nextCell || !await nextCell.BeginCellEditing(e)) + if (CurrentCellSlot == newSlot || GetCellFromSlot(newSlot) is not { } nextCell || !nextCell.BeginCellEditing(e)) { SetIsEditing(false); } @@ -283,7 +283,7 @@ protected async override void OnApplyTemplate() _scrollViewer = GetTemplateChild("ScrollViewer") as ScrollViewer; _headerRowDefinition = GetTemplateChild("HeaderRowDefinition") as RowDefinition; if (_scrollViewer is not null) _scrollViewer.Loaded += OnScrollViewerLoaded; - + if (IsLoaded) { while (ItemsPanelRoot is null) await Task.Yield(); @@ -320,12 +320,12 @@ private void OnScrollViewerLoaded(object sender, RoutedEventArgs e) Source = this }); } - + /// /// Handles the Loaded event of the TableView control. /// private void OnLoaded(object sender, RoutedEventArgs e) - { + { EnsureAutoColumns(); } diff --git a/src/TableViewCell.cs b/src/TableViewCell.cs index 758c3b14..097210f1 100644 --- a/src/TableViewCell.cs +++ b/src/TableViewCell.cs @@ -210,18 +210,14 @@ protected override void OnPointerExited(PointerRoutedEventArgs e) } /// - protected override async void OnTapped(TappedRoutedEventArgs e) + protected override void OnTapped(TappedRoutedEventArgs e) { base.OnTapped(e); - if ((TableView?.IsEditing ?? false) && - TableView.CurrentCellSlot != Slot && - TableView.CurrentCellSlot.HasValue && - TableView.GetCellFromSlot(TableView.CurrentCellSlot.Value) is { } currentCell) + if (TryEndCurrentCellEdit()) { - e.Handled = !TableView.EndCellEditing(TableViewEditAction.Commit, currentCell); - - if (e.Handled) return; + e.Handled = true; + return; } if (TableView?.CurrentCellSlot != Slot || TableView?.LastSelectionUnit is TableViewSelectionUnit.Row) @@ -236,9 +232,15 @@ protected override void OnPointerPressed(PointerRoutedEventArgs e) { base.OnPointerPressed(e); + if (TryEndCurrentCellEdit()) + { + e.Handled = true; + return; + } + if (!KeyboardHelper.IsShiftKeyDown() && TableView is not null) { - TableView.SelectionStartCellSlot = TableView.SelectionUnit is not TableViewSelectionUnit.Row || !IsReadOnly ? Slot : default; ; + TableView.SelectionStartCellSlot = TableView.SelectionUnit is not TableViewSelectionUnit.Row || !IsReadOnly ? Slot : default; TableView.SelectionStartRowIndex = Index; CapturePointer(e.Pointer); } @@ -278,6 +280,19 @@ protected override void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e) } } + private bool TryEndCurrentCellEdit() + { + if ((TableView?.IsEditing ?? false) && + TableView.CurrentCellSlot != Slot && + TableView.CurrentCellSlot.HasValue && + TableView.GetCellFromSlot(TableView.CurrentCellSlot.Value) is { } currentCell) + { + return !TableView.EndCellEditing(TableViewEditAction.Commit, currentCell); + } + + return false; + } + /// /// Gets the height of the horizontal gridlines/>. /// @@ -309,7 +324,7 @@ private double GetHorizontalGridlineHeight() } /// - protected override async void OnDoubleTapped(DoubleTappedRoutedEventArgs e) + protected override void OnDoubleTapped(DoubleTappedRoutedEventArgs e) { var eventArgs = new TableViewCellDoubleTappedEventArgs(Slot, this, Row?.Content); TableView?.OnCellDoubleTapped(eventArgs); @@ -321,7 +336,7 @@ protected override async void OnDoubleTapped(DoubleTappedRoutedEventArgs e) if (!IsReadOnly && TableView is not null && !TableView.IsEditing && !Column?.UseSingleElement is true) { - e.Handled = await BeginCellEditing(e); + e.Handled = BeginCellEditing(e); } else { @@ -370,7 +385,7 @@ private void MakeSelection() /// The event data associated with the editing request. Cannot be null. /// A task that represents the asynchronous operation. The task result is if cell editing was /// successfully started; otherwise, if the operation was canceled. - internal async Task BeginCellEditing(RoutedEventArgs editingArgs) + internal bool BeginCellEditing(RoutedEventArgs editingArgs) { var args = new TableViewBeginningEditEventArgs(this, Row?.Content, Column!, editingArgs); TableView?.OnBeginningEdit(args); From 15847589ac9d281502c9b033bca4534fb097f080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Torsg=C3=A5rden?= Date: Thu, 7 May 2026 19:13:54 +0200 Subject: [PATCH 2/3] Set TableView.IsEditing flag --- src/TableViewCell.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/TableViewCell.cs b/src/TableViewCell.cs index 097210f1..a2f233de 100644 --- a/src/TableViewCell.cs +++ b/src/TableViewCell.cs @@ -287,7 +287,9 @@ private bool TryEndCurrentCellEdit() TableView.CurrentCellSlot.HasValue && TableView.GetCellFromSlot(TableView.CurrentCellSlot.Value) is { } currentCell) { - return !TableView.EndCellEditing(TableViewEditAction.Commit, currentCell); + if (!TableView.EndCellEditing(TableViewEditAction.Commit, currentCell)) return true; + + TableView.SetIsEditing(false); } return false; From df718d1272b02926c83c78542a56efdfebf9acd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Torsg=C3=A5rden?= Date: Fri, 8 May 2026 09:28:50 +0200 Subject: [PATCH 3/3] Invert TryEndCurrentCellEdit return value --- src/TableViewCell.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/TableViewCell.cs b/src/TableViewCell.cs index a2f233de..af37ac0e 100644 --- a/src/TableViewCell.cs +++ b/src/TableViewCell.cs @@ -214,7 +214,7 @@ protected override void OnTapped(TappedRoutedEventArgs e) { base.OnTapped(e); - if (TryEndCurrentCellEdit()) + if (!TryEndCurrentCellEdit()) { e.Handled = true; return; @@ -232,7 +232,7 @@ protected override void OnPointerPressed(PointerRoutedEventArgs e) { base.OnPointerPressed(e); - if (TryEndCurrentCellEdit()) + if (!TryEndCurrentCellEdit()) { e.Handled = true; return; @@ -280,6 +280,11 @@ protected override void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e) } } + /// + /// Tries to end the current edit operation, if any. + /// + /// True if an edit operation was successfully ended, or there is no edit operation. + /// False if the current edit operation can not be ended. private bool TryEndCurrentCellEdit() { if ((TableView?.IsEditing ?? false) && @@ -287,12 +292,12 @@ private bool TryEndCurrentCellEdit() TableView.CurrentCellSlot.HasValue && TableView.GetCellFromSlot(TableView.CurrentCellSlot.Value) is { } currentCell) { - if (!TableView.EndCellEditing(TableViewEditAction.Commit, currentCell)) return true; + if (!TableView.EndCellEditing(TableViewEditAction.Commit, currentCell)) return false; TableView.SetIsEditing(false); } - return false; + return true; } ///