Simplifying INotifyPropertyChanged further

I wrote this post a while back about how to simplify binding properties in Xamarin Forms. Playing around some more with reflection I managed to get rid of the requirement to have a private variable with each property. Instead I create it on the fly which just makes it even easier to create properties now. Let me explain how.

So based on my previous NotifyPropertyChanged.cs class I added a dictionary where I will store all the fields that is created at runtime.

The Get method will create the property based on the calling methods name the first time it’s called for and after that it will simply return the value:

The Set method will take the referred value and set it to the field with the name of the calling method:

When creating a binding property in a class that inherits from NotifyPropertyChanged we can now simply write like this:

Now that was a little bit easier than with the previous version of NotifyPropertyChanged now, was’nt it?<

Previous version:

Leave a Reply

Your email address will not be published. Required fields are marked *