Reputation: 1921
I have a WP 8.1 (native) app and I'm using Caliburn. Micro. In the MainPageViewModel I navigate to the another page, where I want to set some value to the MyObject (property on the MainPageViewModel) and push it back to the MainPageViewModel.
So I navigate to the new page with passing myObject (it's working ok):
navigationService.NavigateToViewModel<AnotherPageViewModel>(myObject)
In the AnotherPageViewModel I set some values to the myObject and I return back to the MainPageViewModel:
navigationService.GoBack();
But how can I pass the changed myObject back to the MainPageViewModel? When I get back, the new instance of myObject in the MainPageViewModel is created.
EDIT: I'd expect that the "changed" myObject will hold the changed values back in the MainPageViewModel after calling GoBack() method, but obviously a new instance is created.
Thanks
Upvotes: 1
Views: 209
Reputation: 16361
Two things come to mind.
If you MainPageView does not set NavigationCacheMode
to Required
then a new instance of MainPageView and MainPageViewModel is created when navigating back. In this case, I would suggest you save the value after selection in AnotherPageViewModel somewhere (settings, etc.) and then load in when MainPageViewModel activates
If you MainPageView sets NavigationCacheMode
to Required
, then MainPageViewModel is not recreated when navigating back. In this case, I would suggest you use messaging (IEventAggregator
). You can send a message to MainPageViewModel informating that the object changed and you may include the whole new object in the message.
Upvotes: 1