0

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?
Paul Michaels
  • 16,185
  • 43
  • 146
  • 269

1 Answers1

0

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

Community
  • 1
  • 1
Stuart
  • 66,722
  • 7
  • 114
  • 165