From 3bba6f91c5dd4bfecd05e00291a792dfd4a37ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Torsg=C3=A5rden?= Date: Thu, 25 Jun 2026 15:31:36 +0200 Subject: [PATCH 1/3] End current edit when IsReadOnly is set to false, on TableView and TableViewColumn --- src/Columns/TableViewColumn.cs | 25 ++++++++++++++++++++++--- src/TableView.Properties.cs | 8 ++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Columns/TableViewColumn.cs b/src/Columns/TableViewColumn.cs index 572c71d..66f0346 100644 --- a/src/Columns/TableViewColumn.cs +++ b/src/Columns/TableViewColumn.cs @@ -499,8 +499,6 @@ private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChan column.OwningCollection.HandleColumnPropertyChanged(column, nameof(MaxWidth)); else if (e.Property == ActualWidthProperty) column.OwningCollection.HandleColumnPropertyChanged(column, nameof(ActualWidth)); - else if (e.Property == IsReadOnlyProperty) - column.OwningCollection.HandleColumnPropertyChanged(column, nameof(IsReadOnly)); else if (e.Property == VisibilityProperty) column.OwningCollection.HandleColumnPropertyChanged(column, nameof(Visibility)); else if (e.Property == OrderProperty) @@ -508,6 +506,27 @@ private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChan } } + /// + /// Handles changes to the IsReadOnly property. + /// + private static void OnIsReadOnlyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is TableViewColumn column) + { + if (column.TableView is TableView tableView && + tableView is not null && + tableView.IsEditing && + tableView.CurrentCellSlot is not null && + tableView.GetCellFromSlot(tableView.CurrentCellSlot.Value) is { } currentCell && + tableView.EndCellEditing(TableViewEditAction.Cancel, currentCell)) + { + column.TableView.SetIsEditing(false); + } + + column.OwningCollection?.HandleColumnPropertyChanged(column, nameof(IsReadOnly)); + } + } + /// /// Handles changes to the CanFilter property. /// @@ -587,7 +606,7 @@ public string? SortMemberPath /// /// Identifies the IsReadOnly dependency property. /// - public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register(nameof(IsReadOnly), typeof(bool), typeof(TableViewColumn), new PropertyMetadata(false, OnPropertyChanged)); + public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register(nameof(IsReadOnly), typeof(bool), typeof(TableViewColumn), new PropertyMetadata(false, OnIsReadOnlyChanged)); /// /// Identifies the Visibility dependency property. diff --git a/src/TableView.Properties.cs b/src/TableView.Properties.cs index 8b6fc07..585394e 100644 --- a/src/TableView.Properties.cs +++ b/src/TableView.Properties.cs @@ -943,6 +943,14 @@ private static void OnIsReadOnlyChanged(DependencyObject d, DependencyPropertyCh { tableView.OnIsReadOnlyChanged(e); + if (tableView.IsEditing && + tableView.CurrentCellSlot is not null && + tableView.GetCellFromSlot(tableView.CurrentCellSlot.Value) is { } currentCell && + tableView.EndCellEditing(TableViewEditAction.Cancel, currentCell)) + { + tableView.SetIsEditing(false); + } + if ((tableView.SelectionMode is ListViewSelectionMode.None || tableView.SelectionUnit is TableViewSelectionUnit.Row) && tableView.IsReadOnly) From 89dfb73699bd6735a43feb77c9c40453d84add5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Torsg=C3=A5rden?= Date: Thu, 25 Jun 2026 15:34:43 +0200 Subject: [PATCH 2/3] Cleanup --- src/Columns/TableViewColumn.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Columns/TableViewColumn.cs b/src/Columns/TableViewColumn.cs index 66f0346..90c3469 100644 --- a/src/Columns/TableViewColumn.cs +++ b/src/Columns/TableViewColumn.cs @@ -520,7 +520,7 @@ tableView.CurrentCellSlot is not null && tableView.GetCellFromSlot(tableView.CurrentCellSlot.Value) is { } currentCell && tableView.EndCellEditing(TableViewEditAction.Cancel, currentCell)) { - column.TableView.SetIsEditing(false); + tableView.SetIsEditing(false); } column.OwningCollection?.HandleColumnPropertyChanged(column, nameof(IsReadOnly)); From d2bb3245f00db54a43a296cd88e52da0d8fdb6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Torsg=C3=A5rden?= Date: Thu, 25 Jun 2026 15:35:35 +0200 Subject: [PATCH 3/3] Cleanup --- src/Columns/TableViewColumn.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Columns/TableViewColumn.cs b/src/Columns/TableViewColumn.cs index 90c3469..3b9a5f2 100644 --- a/src/Columns/TableViewColumn.cs +++ b/src/Columns/TableViewColumn.cs @@ -514,7 +514,6 @@ private static void OnIsReadOnlyChanged(DependencyObject d, DependencyPropertyCh if (d is TableViewColumn column) { if (column.TableView is TableView tableView && - tableView is not null && tableView.IsEditing && tableView.CurrentCellSlot is not null && tableView.GetCellFromSlot(tableView.CurrentCellSlot.Value) is { } currentCell &&