Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Fix Included) Does not update all bindings in VM when passing Null or String.Empty #39

Open
BlackHatCS opened this issue Mar 14, 2020 · 2 comments

Comments

@BlackHatCS
Copy link

The original INotifyPropertyChanged allows a user to pass a PropertyChangedEventArgs of null or String.Empty as a shorthand for updating all registered bindings on the current ViewModel.

After looking over your code I found re-enabling this was VERY simple.

Inside PropertyWatcher.cs at the bottom you have:

private void propertyOwner_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == propertyName) { action(); } }

By simply adding "|| String.IsNullOrEmpty(e.PropertyName)" to the if statement the expected behavior can be achieved. Since the PropertyWatcher class is already designed to be limited to the scope of the current view model, no further code is needed.

private void propertyOwner_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == propertyName || String.IsNullOrEmpty(e.PropertyName)) { action(); } }

@RoryDungan
Copy link
Contributor

That's interesting. When do you think this would be useful? I generally try to avoid firing events unless I know they're definitely necessary but I'd consider adding this if there's a good use-case for it.

@BlackHatCS
Copy link
Author

The most common example is when most of your fields are linked to an object, and that object has changed. Basically, instead of having to maintain a list of things to update you can simply pass null to fire to all registered listeners at the current scope.

This is also the normal behavior for PropertyChanged in WPF and Silverlight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants