使用 Mvvmcross 导航时如何接收包 5.x

How to receive bundle when navigating with Mvvmcross 5.x

我是 Android 编程的新手。 我选择了 MvvmCross 5.x 作为我的框架。 我想我明白如何从 ViewModel 发送 一个 'complex' 对象 一个字典(包):

Task Navigate<TParameter>(IMvxViewModel<TParameter> viewModel,
                          TParameter param, 
                          IMvxBundle presentationBundle = null);

如何接收导航到ViewModel中的捆绑包?
也就是说,用 dictionary/bundle?

调用什么方法

您用于导航的 presentationBundle 参数是 ViewModelRequest 对象的一部分,它被传递给 MvxViewPresenterShow 方法。您可以在您的平台上创建视图呈现器的自定义实现,并使用 PresentationBundle 自定义导航转换的外观或修改导航堆栈。

查看 ViewModelRequest 源代码 on GitHub。 属性 PresentationValues 将包含您在导航中传递的包。以下是 Android:

上自定义视图呈现器的示例实现
class CustomViewPresenter : MvxAndroidViewPresenter
{
    public CustomViewPresenter(IEnumerable<Assembly> androidViewAssemblies)
              : base(androidViewAssemblies)
    {
    }

    public override void Show(MvxViewModelRequest request)
    {
        if (request.PresentationValues.ContainsKey("something"))
        {
            //handle presentation value
        }
        base.Show(request);
    }
}

您可以在使用 ViewModelRequest 的演示器中覆盖更多方法,然后您可以在其中访问 PresentationValues 属性。这些对于每个平台都是特定的,并且取决于正在执行的导航类型。在 Android 上,您有 ShowActivityShowDialogFragmentShowFragment 等。您也可以在 MvvmCross Github 上看到 MvxAndroidViewPresenter 的默认实现。

您可以看到一个很好的示例,说明如何在 this blog post by the awesome Greg Shackles. He also has a nice introduction 中使用带有 PresentationBundle 的自定义 ViewPresenter 来查看演示者。