This project is read-only.

Navigating Back

Nov 5, 2012 at 3:30 PM

I have several instances in my app where users click an item, edit some information, then navigate back to the previous page.  Problem is, the data doesn't update on the previous screen. 

I was thinking about using the built in Messenger from MVVM Light to accomplish this.  So say when a user navigates back, broadcast changes via messenger and register my first vm to receive the change message from the second and update itself.  Or better yet, since all I really want to do is "raise property changed" on my changed object I could use the MVVM Light version of the RaisePropertyChanged that broadcasts out and again just grab it on my other VM.

My question is, is there an easier way to do this?  I tried overriding the OnNavigatedTo event in my view, but it never fires because, I assume, Okra took that over.  Is there someway to intercept some event when navigating back?  IActivatable's Activate() doesn't seem to fire, nor anything else I try to breakpoint.  Or is my messaging idea the recommended way?

Thanks again

Nov 6, 2012 at 1:31 PM

Adamaka,

Regarding OnNavigatedTo events, Okra provides an alternative mechanism that is designed with MVVM based apps in mind. All you have to do is implement the Okra.Navigation.INavigationAware interface on your view-model and the framework should detect this and call the NavigatedTo(...) and NavigatingFrom(...) methods as you would expect.

Alternatively using the MVVM Light messenger should work fine.

As a third option (although a little more complex it is the method I use in my own apps) is to introduce what I call a DataModel that wraps the existing model in an INotifyPropertyChanged wrapper. For example if you were browsing a list of photos, the photo information for each item would be stored in a PhotoDataModel (initialized with the details from the file/web API call). Each of these data models are stored in a cache indexed by a unique ID for each photo - therefore the application only ever has one shared instance of a PhotoDataModel for each photo. When navigating to the details page I pass the photo ID, and the details page pulls the same PhotoDataModel from the cache. When edits are made these are made to the data model which raises PropertyChanged notifications. Since both the main list page and the details page are referring to the same data model instance then data binding should update both automatically.

All three options should work so pick what you prefer for your situation.

Regards,

    Andy

Nov 9, 2012 at 3:18 PM

Thanks again Andy.  I was already doing something similar to your photo situation already, but it doesn't cover anything in my case.  Inheriting INavigationAware worked for me though.