Maks
Maks

Reputation: 2955

MvvmCross Navigate From ViewModel Event

I read about "ViewModel to ViewModel navigation" and "View Model Lifecycle" from here: https://github.com/MvvmCross/MvvmCross/wiki/ViewModel--to-ViewModel-navigation https://github.com/MvvmCross/MvvmCross/wiki/View-Model-Lifecycle

I can use Init() or Start() methods to initialise current ViewModel. Also I can pass parameters from one ViewModel to another and receive it in the Init() method.

So my question: When I created windows phone apps I used "NavigateTo" and "NavigateFrom" methods. Init() is similar to "NavigateTo". But I didn't find alternative for "NavigateFrom" method in mvvmcross and I don't know how to reload data when I move 'back' by "Close(this)" or using back button on windows phone.

Could you hint me?

Thanks in advance!

updated

I found out that Messenger (MvvmCross plugin) can help me with informing first ViewModel, when an other second ViewModel has changed data (for example add an item to a collection). So when the second ViewModel add a new item, first ViewModel reloads the data in the OnCollectionChanged(CollectionChangedMessage obj) method.

Stuart showed how to work with this plugin in the NPlus1DaysOfMvvmCross/N-13-CollectABull-Part2. Link here: https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-13-CollectABull-Part2

Upvotes: 1

Views: 2435

Answers (1)

Stuart
Stuart

Reputation: 66882

But I didn't find alternative for "NavigateFrom" method in mvvmcross and I don't know how to reload data when I move 'back' by "Close(this)" or using back button on windows phone.

In general, you don't need to reload data in this event - because the ViewModel is already created and initialised from the previous navigation in the forwards direction.

If you do want to do some refresh of the ViewModel when navigating back, then the IVisible pattern in the N=42 video may help but you'll need to add this to your View and ViewModel yourself - see http://slodge.blogspot.co.uk/2013/11/n42-is-my-viewmodel-visible-can-i-kill.html

Upvotes: 1

Related Questions