@@ -508,8 +508,6 @@ private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChan
508508 column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( MaxWidth ) ) ;
509509 else if ( e . Property == ActualWidthProperty )
510510 column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( ActualWidth ) ) ;
511- else if ( e . Property == IsReadOnlyProperty )
512- column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( IsReadOnly ) ) ;
513511 else if ( e . Property == VisibilityProperty )
514512 column . OwningCollection . HandleColumnPropertyChanged ( column , nameof ( Visibility ) ) ;
515513 else if ( e . Property == OrderProperty )
@@ -528,6 +526,27 @@ private static void OnColumnAutoWidthModeChanged(DependencyObject d, DependencyP
528526 }
529527 }
530528
529+ /// <summary>
530+ /// Handles changes to the IsReadOnly property.
531+ /// </summary>
532+ private static void OnIsReadOnlyChanged ( DependencyObject d , DependencyPropertyChangedEventArgs e )
533+ {
534+ if ( d is TableViewColumn column )
535+ {
536+ if ( column . TableView is TableView tableView &&
537+ tableView . IsReadOnly &&
538+ tableView . IsEditing &&
539+ tableView . CurrentCellSlot is not null &&
540+ tableView . GetCellFromSlot ( tableView . CurrentCellSlot . Value ) is { } currentCell &&
541+ tableView . EndCellEditing ( TableViewEditAction . Cancel , currentCell ) )
542+ {
543+ tableView . SetIsEditing ( false ) ;
544+ }
545+
546+ column . OwningCollection ? . HandleColumnPropertyChanged ( column , nameof ( IsReadOnly ) ) ;
547+ }
548+ }
549+
531550 /// <summary>
532551 /// Handles changes to the CanFilter property.
533552 /// </summary>
@@ -612,7 +631,7 @@ public string? SortMemberPath
612631 /// <summary>
613632 /// Identifies the IsReadOnly dependency property.
614633 /// </summary>
615- public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty . Register ( nameof ( IsReadOnly ) , typeof ( bool ) , typeof ( TableViewColumn ) , new PropertyMetadata ( false , OnPropertyChanged ) ) ;
634+ public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty . Register ( nameof ( IsReadOnly ) , typeof ( bool ) , typeof ( TableViewColumn ) , new PropertyMetadata ( false , OnIsReadOnlyChanged ) ) ;
616635
617636 /// <summary>
618637 /// Identifies the Visibility dependency property.
0 commit comments