Skip to content

Commit

Permalink
feat: Add support for INPC(String.Empty) to notify all object's prope…
Browse files Browse the repository at this point in the history
…rties
  • Loading branch information
jeromelaban committed Jul 3, 2020
1 parent acd1f32 commit 308eb77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
40 changes: 39 additions & 1 deletion src/Uno.UI.Tests/BinderTests/Given_Binder.inpc.cs
Expand Up @@ -56,7 +56,8 @@ public void When_INPC_Update_SameReference_Converter()
var SUT = new Binder_INPC_Data();
SUT.SetBinding(
Binder_INPC_Data.MyValueProperty,
new Binding {
new Binding
{
Path = new PropertyPath("Value"),
Converter = new Binder_INPC_DummyConverter()
});
Expand All @@ -73,6 +74,34 @@ public void When_INPC_Update_SameReference_Converter()
Assert.AreEqual(4, master.ValueGetCount);
Assert.AreEqual(0, master.ValueSetCount);
}

[TestMethod]
public void When_INPC_Raise_All_Updated()
{
var SUT = new Binder_INPC_Data();
SUT.SetBinding(
Binder_INPC_Data.MyValueProperty,
new Binding
{
Path = new PropertyPath("Class1.Value")
});

SUT.SetBinding(
Binder_INPC_Data.MyValue2Property,
new Binding
{
Path = new PropertyPath("Value"),
Converter = new Binder_INPC_DummyConverter()
});

var master = new Binder_INPC_Base_Class();
SUT.DataContext = master;

master.RaiseAllUpdated();

Assert.AreEqual(SUT.MyValue, master.Class1.Value);
Assert.AreEqual(SUT.MyValue2, master.Value);
}
}

public partial class Binder_INPC_Data : DependencyObject
Expand All @@ -92,6 +121,15 @@ private void OnMyValueChanged(string oldValue, string newValue)
{
MyValuePropertyValueDuringChange = MyValue;
}

public string MyValue2
{
get => GetMyValue2Value();
set => SetMyValue2Value(value);
}

[GeneratedDependencyProperty(DefaultValue = "")]
public static DependencyProperty MyValue2Property { get; } = CreateMyValue2Property();
}

public class Binder_INPC_Base_Class : Binder_INPC_BaseViewModel
Expand Down
6 changes: 3 additions & 3 deletions src/Uno.UI/DataBinding/BindingPath.cs
Expand Up @@ -355,11 +355,11 @@ private static IDisposable SubscribeToNotifyPropertyChanged(ManagedWeakReference

System.ComponentModel.PropertyChangedEventHandler handler = (s, args) =>
{
if (args.PropertyName == propertyName)
if (args.PropertyName == propertyName || args.PropertyName == string.Empty)
{
if (typeof(BindingPath).Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
typeof(BindingPath).Log().Debug("Property changed for {0} on [{1}]".InvariantCultureFormat(propertyName, dataContextReference.Target?.GetType()));
typeof(BindingPath).Log().Debug($"Property changed for {propertyName} on [{dataContextReference.Target?.GetType()}]");
}
if (!newValueActionWeak.IsDisposed)
Expand Down Expand Up @@ -437,7 +437,7 @@ public object DataContext
// detrimental to the use of INPC events processing.
// In case of an INPC, the bindings engine must reevaluate the path completely from the raising point, regardless
// of the reference being changed.
if(FeatureConfiguration.Binding.IgnoreINPCSameReferences && DependencyObjectStore.AreDifferent(DataContext, value))
if(FeatureConfiguration.Binding.IgnoreINPCSameReferences && !DependencyObjectStore.AreDifferent(DataContext, value))
{
return;
}
Expand Down

0 comments on commit 308eb77

Please sign in to comment.