Skip to content

Commit

Permalink
Merge pull request #328 from AvaloniaUI/fixes/327-stringformat-model-…
Browse files Browse the repository at this point in the history
…update

Fix text cell StringFormat not being displayed.
  • Loading branch information
maxkatz6 authored Dec 20, 2024
2 parents c4c078b + 441e1f2 commit 666b174
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected override void OnModelPropertyChanged(object? sender, PropertyChangedEv
try
{
_modelValueChanging = true;
Value = Model?.Value?.ToString();
UpdateValue();
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,55 @@ static void AssertRealizedCells(TreeDataGrid target)
AssertRealizedCells(target);
}

[AvaloniaFact(Timeout = 10000)]
public void Should_Use_TextCell_StringFormat()
{
var (target, items) = CreateTarget(columns: new IColumn<Model>[]
{
new TextColumn<Model, string?>("Title", x => x.Title, options: new()
{
StringFormat = "Hello {0}"
}),
});

var rows = target.RowsPresenter!
.GetVisualChildren()
.Cast<TreeDataGridRow>()
.ToList();

Assert.Equal(10, rows.Count);

for (var i = 0; i < rows.Count; i++)
{
var cell = Assert.IsType<TreeDataGridTextCell>(
Assert.Single(rows[i].CellsPresenter!.GetVisualChildren().Cast<TreeDataGridCell>()));
Assert.Equal($"Hello Item {i}", cell.Value);
}
}

[AvaloniaFact(Timeout = 10000)]
public void Should_Use_TextCell_StringFormat_When_Model_Is_Updated()
{
var (target, items) = CreateTarget(columns: new IColumn<Model>[]
{
new TextColumn<Model, string?>("Title", x => x.Title, options: new()
{
StringFormat = "Hello {0}"
}),
});

var rows = target.RowsPresenter!
.GetVisualChildren()
.Cast<TreeDataGridRow>()
.ToList();

Assert.Equal(10, rows.Count);
items[1].Title = "World";
var cell = Assert.IsType<TreeDataGridTextCell>(target.TryGetCell(0, 1));

Assert.Equal("Hello World", cell.Value);
}

public class RemoveItems
{
[AvaloniaFact(Timeout = 10000)]
Expand Down

0 comments on commit 666b174

Please sign in to comment.