Skip to content

Commit

Permalink
Don't write value to model when change comes from model.
Browse files Browse the repository at this point in the history
If a changed value comes from the model, then we shouldn't be writing it back to the model. Usually this would be a no-op but when a `StringFormat` is applied it causes the formatted value to be sent back to the underlying data model, and if the `StringFormat` is not round-trippable causes an exception.
  • Loading branch information
grokys committed Nov 20, 2024
1 parent dcfffd6 commit cd252c0
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class TreeDataGridTextCell : TreeDataGridCell

private string? _value;
private TextBox? _edit;
private bool _modelValueChanging;
private TextTrimming _textTrimming = TextTrimming.CharacterEllipsis;
private TextWrapping _textWrapping = TextWrapping.NoWrap;
private TextAlignment _textAlignment = TextAlignment.Left;
Expand All @@ -54,7 +55,7 @@ public string? Value
get => _value;
set
{
if (SetAndRaise(ValueProperty, ref _value, value) && Model is ITextCell cell)
if (SetAndRaise(ValueProperty, ref _value, value) && Model is ITextCell cell && !_modelValueChanging)
cell.Text = _value;
}
}
Expand Down Expand Up @@ -109,7 +110,17 @@ protected override void OnModelPropertyChanged(object? sender, PropertyChangedEv
base.OnModelPropertyChanged(sender, e);

if (e.PropertyName == nameof(ITextCell.Value))
Value = Model?.Value?.ToString();
{
try
{
_modelValueChanging = true;
Value = Model?.Value?.ToString();
}
finally
{
_modelValueChanging = false;
}
}
}
}
}

0 comments on commit cd252c0

Please sign in to comment.