luismts / ValidationRulesPlugin

Create and validate property rules for all your Xamarin and Windows apps and improve the quality of your data.
https://luismts.com/
MIT License
68 stars 26 forks source link

NotifyPropertyChanged not triggered correctly #18

Closed alexstanfx closed 2 years ago

alexstanfx commented 2 years ago

Bug Information

Version Number of Plugin: 1.4.0 Device Tested On: none Simulator Tested On: iPhone 13 Pro iOS 15.2 Version of VS: VS for Mac 8.10.19 (build 2) Version of Xamarin: 5.0.0.2337 Versions of other things you are using:

Steps to reproduce the Behavior

In a simple page, create an Entry and a Label, both bound to the same Validatable(string)'s "Value" member.

Expected Behavior

When writing into the Entry, the Label's text should update automatically.

Actual Behavior

The Label's text is not updated, because "Value"'s setter also sets "ValueFormatted" property which in turn sets the backing field of "Value" and when "Value"'s setter wants to trigger the notify property changed event, it finds out that its own backing field is equal to the new value passed to the setter, so it simply returns false.

prtected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
      if (EqualityComparer<T>.Default.Equals(storage, value))
      {
          return false;
      }

      storage = value;
      NotifyPropertyChanged(propertyName);

      return true;
}

Removing "return false" fixes the issue.

luismts commented 2 years ago

Close with #19