rehansaeed.github.io icon indicating copy to clipboard operation
rehansaeed.github.io copied to clipboard

[Comment] Model-View-ViewModel (MVVM) - Part 3 - INotifyPropertyChanged

Open RehanSaeed opened this issue 5 years ago • 16 comments

https://rehansaeed.com/model-view-viewmodel-mvvm-part3-inotifypropertychanged/

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Mahgnilloc 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;

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed 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 SetProperty functions though

if (equal()) return false;

Thanks for the comment Mahgnilloc. I've updated the code to reflect your comment.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Rached 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.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2015-08-18 12:07:54

Your blog series on mvvm is helping me a lot, thanks.. the SetProperty should be bool instead of void.

Well spotted, thanks. Fixed.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Manthravadi, Siva Harsha Vardhan Manthravadi, Siva Harsha Vardhan commented on 2015-10-17 17:48:17

Disposable cannot be inherited anymore ...do you see any other alternatives?

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2015-10-21 17:11:49

Disposable cannot be inherited anymore ...do you see any other alternatives?

Not sure what you mean. Have you set the class to sealed?

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Dieter 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

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed 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.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Dieter 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); }

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed 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.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Ole Kristian 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?

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2017-11-13 09:16:30

Maybe update the example to reflect this change?

Thanks, have done so!

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Bilal 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.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed 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.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Steve Greene 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.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed

Muhammad Rehan Saeed Muhammad Rehan Saeed commented on 2019-08-02 16:28:51

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.

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.

RehanSaeed avatar May 12 '20 10:05 RehanSaeed