Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/Columns/TableViewColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,15 +499,33 @@ 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)
column.OwningCollection.HandleColumnPropertyChanged(column, nameof(Order));
}
}

/// <summary>
/// Handles changes to the IsReadOnly property.
/// </summary>
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));
}
}

/// <summary>
/// Handles changes to the CanFilter property.
/// </summary>
Expand Down Expand Up @@ -587,7 +605,7 @@ public string? SortMemberPath
/// <summary>
/// Identifies the IsReadOnly dependency property.
/// </summary>
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));

/// <summary>
/// Identifies the Visibility dependency property.
Expand Down
8 changes: 8 additions & 0 deletions src/TableView.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading