1

I use MvvmCross library for cross platform mobile development.

I've got the page with chat lists (ChatListPageViewModel). It loads chats from the container in the Init() method.

From this page you can navigate to the page which adds new chat to container (AddChatPageViewModel).

When the chat is added, I call Close(this) in AddChatPageViewModel. So, I automatically navigate to ChatListPageViewModel, but Init() method is not called at this moment and I cannot refresh my data. How can I handle this?

4

1 回答 1

1

Init 保留用于初始化新的视图模型 - 它并不是真正为刷新现有视图模型而设计的。

但是,我认为您可以通过以下方式实现您正在寻找的应用程序流类型:

  • 添加聊天时从 AddChatViewModel 发送消息
  • 或编写自定义 OnNavigatedTo、ViewDidAppear、OnResume 处理程序并使用它们在您的聊天视图模型上调用自定义方法

第一个方案的一个示例在 CollectABull N+1 示例中 - https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-13-CollectABull-Part2 - 当收集服务更改时,它会广播一条消息,允许订阅 ViewModels 以更新 - 请参阅http://mvvmcross.wordpress.com了解演练视频。

于 2013-07-11T05:58:21.390 回答