问题描述
我从这里阅读有关从ViewModel到ViewModel的导航"和"View Model Lifecycle"的信息: https://github.com/MvvmCross/MvvmCross/wiki/ViewModel- -to-ViewModel-导航 https://github.com/MvvmCross/MvvmCross/wiki/View-Model-Lifecycle
I read about "ViewModel to ViewModel navigation" and "View Model Lifecycle" from here:https://github.com/MvvmCross/MvvmCross/wiki/ViewModel--to-ViewModel-navigationhttps://github.com/MvvmCross/MvvmCross/wiki/View-Model-Lifecycle
我可以使用Init()或Start()方法来初始化当前的ViewModel.同样,我可以将参数从一个ViewModel传递到另一个ViewModel,并通过Init()方法接收它.
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.
所以我的问题是:创建Windows Phone应用程序时,我使用了"NavigateTo"和"NavigateFrom"方法.Init()类似于"NavigateTo".但是我没有在mvvmcross中找到"NavigateFrom"方法的替代方法,并且当我通过"Close(this)"或在Windows Phone上使用后退"按钮移动后退"时,我也不知道如何重新加载数据.
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.
你能提示我吗?
提前谢谢!
已更新
我发现Messenger(MvvmCross插件)可以帮助我通知第一个ViewModel,而另一个第二个ViewModel更改了数据(例如,将一个项添加到集合中).因此,当第二个ViewModel添加新项时,第一个ViewModel会在OnCollectionChanged(CollectionChangedMessage obj)方法中重新加载数据.
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在NPlus1DaysOfMvvmCross/N-13-CollectABull-Part2中展示了如何使用此插件.链接到这里: https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-13-CollectABull-Part2
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
推荐答案
通常,您无需在此事件中重新加载数据-因为ViewModel已在前向导航中从前一个导航创建并初始化.
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.
如果您确实想在导航时进行ViewModel的刷新,则N = 42视频中的IVisible
模式可能会有所帮助,但您需要自己将其添加到View和ViewModel中-请参见 http://slodge.blogspot .co.uk/2013/11/n42-is-my-viewmodel-visible-can-i-kill.html
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
这篇关于MvvmCross从ViewModel事件导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!