Setting ViewModel for MvxFragment

I am working on an application using Xamarin.Android and MVVMCross , and I am encountering some problems when trying to set the ViewModel (MvxViewModel) for the fragment (MvxFragment).

In my research so far I have found several examples, but they seem to be quite outdated and therefore no longer useful.

https://forums.xamarin.com/discussion/3652/mvvmcross-activity-vs-fragment http://slodge.blogspot.com/2013/06/n26-fragments-n1-days-of-mvvmcross.html

My specific situation is that I am trying to create an application with drawerlayout that works fine, the problem is that when loading the MvxFragment subclass through the FragmentManager, the ViewModel is not connected to the view (ViewModel was correctly connected before I changed the view from Activity to fragment.)

When I was looking through the documentation on how to do this, I found the following code

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var ignored = base.OnCreateView(inflater, container, savedInstanceState);
        return this.BindingInflate(Resource.Layout.Fragment_Detail, null);
    }

the problem is that there is no method in MvxFragment BindingInflate(...).

Here is what my OnCreateView looks like

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var ignored = base.OnCreateView(inflater, container, savedInstanceState);
        var view = inflater.Inflate(Resource.Layout.HomeView, container, false);
        return view;
    }

So my question boils down to this: How do I link my ViewModel to my view, which is an extension of MVxFragment?

Not sure if this helps, but I create such a snippet

var fragment = new HomeView();
FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, fragment).Commit();
+4
1

, , . , , .

using Cirrious.MvvmCross.Binding.Droid.BindingContext;
+2

All Articles