Skip to content

Commit

Permalink
Added passing test for #16084.
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys committed Jul 3, 2024
1 parent bc4355d commit 9cfdce8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Data.Converters;
using Avalonia.UnitTests;
using Xunit;

#nullable enable
Expand Down Expand Up @@ -203,6 +204,46 @@ public void Converter_Can_Return_BindingNotification()
Assert.Equal("1,2,3-BindingNotification", target.Text);
}

[Fact]
public void Converter_Should_Be_Called_On_PropertyChanged_Even_If_Property_Not_Changed()
{
// Issue #16084
var data = new TestModel();
var target = new TextBlock { DataContext = data };

var binding = new MultiBinding
{
Converter = new TestModelMemberConverter(),
Bindings =
{
new Binding(),
new Binding(nameof(data.NotifyingValue)),
},
};

target.Bind(TextBlock.TextProperty, binding);
Assert.Equal("0", target.Text);

data.NonNotifyingValue = 1;
Assert.Equal("0", target.Text);

data.NotifyingValue = new object();
Assert.Equal("1", target.Text);
}

private partial class TestModel : NotifyingBase
{
private object? _notifyingValue;

public int? NonNotifyingValue { get; set; } = 0;

public object? NotifyingValue
{
get => _notifyingValue;
set => SetField(ref _notifyingValue, value);
}
}

private class ConcatConverter : IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
Expand Down Expand Up @@ -237,5 +278,18 @@ private class BindingNotificationConverter : IMultiValueConverter
string.Join(",", values) + "-BindingNotification");
}
}

private class TestModelMemberConverter : IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
if (values[0] is not TestModel model)
{
return string.Empty;
}

return model.NonNotifyingValue.ToString();
}
}
}
}

0 comments on commit 9cfdce8

Please sign in to comment.