0

我有 PageA + ViewModelA 和 PageB + ViewModelB。

我从 A 调用 PushAsync(B),编辑一些数据,然后调用 PopAsync()。

所以现在 B 关闭,用户返回 A。

但是在 B 用户改变了一些状态,那应该在 A 上更新。通知 A 更新状态的正确方法是什么(最好能够访问 ViewModelB)。

方法:

1. In B call PopAsync(), from NavigationStack get ViewModelA and manually trigger some update method
2. [doesn't work for me] In A call PushAsync(B) and wait until B becomes closed, so after that perform update with access to VMB (PushAsync doesn't lock A, so this approach doesn't work)

似乎这两种方法都不正确。

4

1 回答 1

1

通常在 MVVM 环境中,当您需要向其他 ViewModel 发出“信号”更改时,您会使用消息传递系统。根据 MVVM 框架,您需要查看可用的类。

在 xamarin 表单中,您将拥有消息中心 https://developer.xamarin.com/guides/cross-platform/xamarin-forms/messaging-center/

于 2015-12-10T09:20:53.667 回答