Skip to content

Commit

Permalink
Merge pull request #315 from AvaloniaUI/fixes/stringformat-exception
Browse files Browse the repository at this point in the history
Don't write value to model when change comes from model.
  • Loading branch information
grokys authored Nov 21, 2024
2 parents dcfffd6 + cd252c0 commit 8196b05
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 8196b05

Please sign in to comment.