From 9cfdce848dafbc6838f5beb7dc0d2351b127dd96 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 3 Jul 2024 14:12:21 +0200 Subject: [PATCH] Added passing test for #16084. --- .../Data/MultiBindingTests.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs b/tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs index d8fc9bae115..9af7323ed48 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs @@ -7,6 +7,7 @@ using Avalonia.Controls; using Avalonia.Data; using Avalonia.Data.Converters; +using Avalonia.UnitTests; using Xunit; #nullable enable @@ -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 values, Type targetType, object? parameter, CultureInfo culture) @@ -237,5 +278,18 @@ private class BindingNotificationConverter : IMultiValueConverter string.Join(",", values) + "-BindingNotification"); } } + + private class TestModelMemberConverter : IMultiValueConverter + { + public object? Convert(IList values, Type targetType, object? parameter, CultureInfo culture) + { + if (values[0] is not TestModel model) + { + return string.Empty; + } + + return model.NonNotifyingValue.ToString(); + } + } } }