diff --git a/src/Columns/TableViewColumn.cs b/src/Columns/TableViewColumn.cs
index 572c71d..3b9a5f2 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,26 @@ 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.IsEditing &&
+ tableView.CurrentCellSlot is not null &&
+ tableView.GetCellFromSlot(tableView.CurrentCellSlot.Value) is { } currentCell &&
+ tableView.EndCellEditing(TableViewEditAction.Cancel, currentCell))
+ {
+ tableView.SetIsEditing(false);
+ }
+
+ column.OwningCollection?.HandleColumnPropertyChanged(column, nameof(IsReadOnly));
+ }
+ }
+
///
/// Handles changes to the CanFilter property.
///
@@ -587,7 +605,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)