MVVM Cross - passing parameters

一笑奈何 提交于 2019-12-11 15:05:57

问题


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);
    }

And here's the code for ViewModel2:

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

    }

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.

So, my questions are:

  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?

回答1:


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



来源:https://stackoverflow.com/questions/24457537/mvvm-cross-passing-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!