0
votes

I am using Mvvmcross crosscore in my project

I am trying to bind my loginviewmodel to the loginviewcontroller

I bound a command for the login button. the app waits until it gets a login response, which is stored in the loginViewModel itself..

How can I communicate this to the loginviewcontroller --- regarding the login status and login error message if any

Can I access the viewmodel datacontext inside my loginviewcontroller ??? and how ?

What is the best approach to communication any items in the viewmodel back ( I basically mean all the NON-UI binding items)

2
It would be easier to answer, this question if you posted some code showing what you are doing. - Stuart

2 Answers

1
votes

I am using Mvvmcross crosscore in my project

I'm assuming from this that you followed the CrossLight sample N=39.

Can I access the viewmodel datacontext inside my loginviewcontroller ??? and how ?

If you followed N=39. then you can access the DataContext using the property called DataContext - see https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/blob/master/N-39-CrossLight-Touch/CrossLightTouch/MyViewController.cs#L33

    public object DataContext
    {
        get { return BindingContext.DataContext; }
        set { BindingContext.DataContext = value; }
    }

Beyond this, there are many other examples in the N+1 videos which demonstrate how to communicate between ViewModels and Views including error messages and loading dialogs - e.g. N=34 shows one implementation of progress dialogs - https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-34-Progress

A complete index of N+1 videos is available on http://mvvmcross.wordpress.com

Obviously not all of these are appropriate for your CrossLight approach to development, but this is where you can allow your custom mvvm approach to fill the gap - it's code for you to write in your custom framework.

1
votes

One of the best methods solving viewmodel interdependencies is using a loosely coupled approch using the MessageBus/Event Aggregator pattern. There's a plugin for MvvmCross. Or you could use the excellent TinyMessenger.

In principle when using this approach, you no longer establish hard references between the publisher and consumers of arbitrary notifications. Instead notifications get published on a message bus and every one is free to listen and subscribe.