rehansaeed.github.io
rehansaeed.github.io copied to clipboard
[Comment] Model-View-ViewModel (MVVM) - Part 3 - INotifyPropertyChanged
https://rehansaeed.com/model-view-viewmodel-mvvm-part3-inotifypropertychanged/
Mahgnilloc commented on 2014-09-03 07:34:00
Thanks, your wrapped property really helped me.
I think you missed out the equals check in the two SetProperty functions though
if (equal()) return false;
Muhammad Rehan Saeed commented on 2014-09-04 08:03:54
Thanks, your wrapped property really helped me.
I think you missed out the equals check in the two
SetPropertyfunctions thoughif (equal()) return false;
Thanks for the comment Mahgnilloc. I've updated the code to reflect your comment.
Rached commented on 2015-08-17 16:44:57
Thanks for the comment Mahgnilloc. I've updated the code to reflect your comment.
Your blog series on mvvm is helping me a lot, thanks.. the SetProperty should be bool instead of void.
Muhammad Rehan Saeed commented on 2015-08-18 12:07:54
Your blog series on mvvm is helping me a lot, thanks.. the
SetPropertyshould be bool instead of void.
Well spotted, thanks. Fixed.
Manthravadi, Siva Harsha Vardhan commented on 2015-10-17 17:48:17
Disposable cannot be inherited anymore ...do you see any other alternatives?
Muhammad Rehan Saeed commented on 2015-10-21 17:11:49
Disposablecannot be inherited anymore ...do you see any other alternatives?
Not sure what you mean. Have you set the class to sealed?
Dieter commented on 2016-01-16 13:50:00
Hello Rehan,
Great implementation.
Just a minor finding:
I guess there's a typo in your 'Dealing with Wrapped Objects' example. The == and = should be flipped.
Have a great weekend Dieter
Muhammad Rehan Saeed commented on 2016-01-26 08:43:59
Hello Rehan,
Great implementation.
Just a minor finding: I guess there's a typo in your 'Dealing with Wrapped Objects' example. The
==and=should be flipped.Have a great weekend Dieter
Actually no, the second delegate is passed to determine whether the two objects are equal. Only if they are equal, do we raise a property changed event.
Dieter commented on 2016-05-26 08:56:55
Actually no, the second delegate is passed to determine whether the two objects are equal. Only if they are equal, do we raise a property changed event.
Hello Rehan,
Are you sure? The procedure is
protected Boolean SetProperty(Func equal, Action action, [CallerMemberName] String propertyName = null)
So the first delegate seems to be the equality check.
Testing your example only works if I'm using
set { this.SetProperty(() => this.catCount.Count == value, () => this.catCount.Count = value); }
Instead of
set { this.SetProperty(() => this.catCount.Count = value, () => this.catCount.Count == value); }
Muhammad Rehan Saeed commented on 2016-05-26 17:16:08
Hello Rehan,
are you sure? The procedure is
protected Boolean SetProperty(Func equal, Action action, [CallerMemberName] String propertyName = null)So the first delegate seems to be the equality check.
Testing your example only works if I'm using
set { this.SetProperty(() => this.catCount.Count == value, () => this.catCount.Count = value); }Instead of
set { this.SetProperty(() => this.catCount.Count = value, () => this.catCount.Count == value); }
Scratch that, you are absolutely correct sir! It's been some time since I've looked at this code.
Ole Kristian commented on 2017-10-23 22:43:15
Scratch that, you are absolutely correct sir! It's been some time since I've looked at this code.
Maybe update the example to reflect this change?
Muhammad Rehan Saeed commented on 2017-11-13 09:16:30
Maybe update the example to reflect this change?
Thanks, have done so!
Bilal commented on 2019-04-24 12:44:31
I want to ask you if I could have the permission to use your code freely.
Muhammad Rehan Saeed commented on 2019-05-03 13:44:09
I want to ask you if I could have the permission to use your code freely.
The code in this post is MIT licensed.
Steve Greene commented on 2019-07-31 19:39:02
This INotifyPropertyChanged base implementation seems very useful to me - thank you!
I'm confused about the Debug.Assert condition shown:
string.IsNullOrEmpty(propertyName) || (this.GetType().GetRuntimeProperty(propertyName) != null)
Shouldn't that be like this instead?
(!string.IsNullOrEmpty(propertyName)) && (this.GetType().GetRuntimeProperty(propertyName) != null)
But I'm unfamiliar with the actual meaning of this.GetType().GetRuntimeProperty(propertyName), so I'm just confused.
Muhammad Rehan Saeed commented on 2019-08-02 16:28:51
This
INotifyPropertyChangedbase implementation seems very useful to me - thank you!I'm confused about the
Debug.Assertcondition shown:string.IsNullOrEmpty(propertyName) || (this.GetType().GetRuntimeProperty(propertyName) != null)Shouldn't that be like this instead?
(!string.IsNullOrEmpty(propertyName)) && (this.GetType().GetRuntimeProperty(propertyName) != null)But I'm unfamiliar with the actual meaning of
this.GetType().GetRuntimeProperty(propertyName), so I'm just confused.
A null or empty property name is actually valid. It signals that all of the properties on the view model have changed and that they should be refreshed in the XAML bindings.