Caliburn.Micro & Windows Phone 8.1:如何给导航GoBack()方法传递参数?

Caliburn.Micro & Windows Phone 8.1: How to pass parameters to the navigation GoBack() method?

我有一个 WP 8.1(本机)应用程序并且我正在使用 Caliburn。微。 在 MainPageViewModel 中,我导航到另一个页面,我想在其中为 MyObject 设置一些值(MainPageViewModel 上的属性)并将其推回 MainPageViewModel。

所以我通过传递 myObject 导航到新页面(它工作正常):

navigationService.NavigateToViewModel<AnotherPageViewModel>(myObject)

在 AnotherPageViewModel 中,我为 myObject 设置了一些值,然后 return 返回 MainPageViewModel:

navigationService.GoBack();

但是如何将更改后的 myObject 传递回 MainPageViewModel?当我回来时,在 MainPageViewModel 中创建了 myObject 的新实例。

编辑: 我希望 "changed" myObject 在调用 GoBack() 方法后将更改的值保留在 MainPageViewModel 中,但显然会创建一个新实例。

谢谢

我想到了两件事。

如果您的 MainPageView 未将 NavigationCacheMode 设置为 Required,则在返回时会创建 MainPageView 和 MainPageViewModel 的新实例。在这种情况下,我建议您将选择后的值保存在 AnotherPageViewModel 的某个地方(设置等),然后在 MainPageViewModel 激活时加载

如果 MainPageView 将 NavigationCacheMode 设置为 Required,则在返回时不会重新创建 MainPageViewModel。在这种情况下,我建议您使用消息传递 (IEventAggregator)。您可以向 MainPageViewModel 发送一条消息,告知对象已更改,您可以在消息中包含整个新对象。