MVVM交叉传递参数 [英] MVVM Cross - passing parameters

查看:105
本文介绍了MVVM交叉传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MVVM Cross中的视图模型之间传递对象.这是我要传递的VM的代码:

I'm trying to pass objects across view models in MVVM Cross. Here's the code for the VM that I'm passing from:

    private void CallVM2()
    {
        MyObj newObj = new Myobj();
        IMyService myService = new MyService();

        Dictionary<string, object> p = new Dictionary<string, object>()
        {
            {"MyObj", newObj},
            {"MyService", myService}
        };

        ShowViewModel<ViewModel2>(p);
    }

这是ViewModel2的代码:

And here's the code for ViewModel2:

    public void Init(Dictionary<string, object> p)
    {

    }

好的-我也尝试过InitFromBundle,但是看来我需要Init.我不知道该如何或为什么被调用,但是可以.它不做的是填充参数.

Okay - so I tried InitFromBundle too, but it appears that I need Init. I can't work out how or why this gets called, but it does. What it doesn't do is populate the parameters.

所以,我的问题是:

  1. MVVM框架如何以及为什么调用init(假设这是正确的方法)?
  2. 我应该使用InitFromBundle吗?如果不使用,那是什么意思?
  3. 为什么我的代码没有通过对象字典传递给Init,我该怎么做?
  1. How and why is init called by the MVVM framework (assuming that is the correct method)?
  2. Should I be using InitFromBundle and if not, what is that for?
  3. Why does my code not pass through a dictionary of objects to Init, and how can I make it?

推荐答案

MvvmCross依赖于基础平台导航机制-例如android上的intent和Windows Phone上的url之类的东西.

MvvmCross relies on underlying platform navigation mechanisms - eg things like intents on android and urls on windows phone.

因此,它不支持按对象导航-仅支持一些小的可序列化类型的导航-请参见

Because of this it doesn't support navigation by object - only navigation by a few small serializable types - see https://github.com/MvvmCross/MvvmCross/wiki/ViewModel--to-ViewModel-navigation for more information.

如果您确实想通过更复杂的可序列化对象进行导航,则可以轻松扩展视图模型类以支持此方法-请参见

If you do want to navigate by more complex serializable objects, then you can easily extend your view model classes to support this - see Passing complex navigation parameters with MvvmCross ShowViewModel

这篇关于MVVM交叉传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆