How to force a refresh of an entire view/all fields

Topics: Prism v4 - WPF 4
Sep 9, 2013 at 6:53 PM
Hi, I'm looking for a "best practices" pattern to use.

Scenario is:

Customer view is loaded, all bindings, saves and RaisePropertyChanged working correctly.

User changes a few fields, presses a cancel button.

I want to abort the changes and revert to the current data in the database.

When the user presses cancel I'm currently:
  • Re-fetching the underlying object using a repository pattern. The customer model is then refreshed correctly with the values from the database.
  • There is a reference to the customer model in in the viewModel.
  • Simply refreshing the customer model does not trigger RaisePropertyChanged on the individual properties (I don't expect it to at this point).
Do I have to add a method something like RefreshAllData() which explicitly calls RaisePropertyChanged on all properties?

I have other patterns where pressing cancel closes the view so this is not an issue as the data is refreshed the next time the view is opened.
Sep 9, 2013 at 7:41 PM

Based on my understanding of your scenario I believe you might need to raise the PropertyChanged event for all corresponding the properties. However, you don't need to invoke the RaisePropertyChanged method for each property; instead you could just invoke it with an empty string:
This should raise the PropertyChanged event for all the properties of your view model, forcing the view to refresh all of its bindings.

I hope this helps,

Damian Cherubini
Sep 9, 2013 at 9:02 PM
Works as expected, thanks!