0

I am following this tutorial and the way they used mvxbind for thier Home, Info and third fragments to their respective viewmodels. I tried to do exactly same for my other fragment but I don't know what I am doing wrong but it MvxBind is not working. Here is the code for my viewmodel and layout.

SomeViewModel.cs

public class SomeViewModel : BaseViewModel
{
    public SomeViewModel()
    {

    }

    private MvxCommand someViewModelCommand;

    public MvxCommand SomeViewModelCommand
    {
        get
        {
            someViewModelCommand = someViewModelCommand ?? new MvxCommand(DoSomeViewModel);
            return someViewModelCommand;
        }
    }

    private void DosomeViewModel()
    {
        ShowViewModel<FirstViewModel>();
    }

}

FirstViewModel.cs

public class FirstViewModel : BaseViewModel
{
    public FirstViewModel()
    {
        First = "Some Info for you...";
    }

    public string First
    {
        get;
        private set;
    }
}

Now I have layout something like this: SomeLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<Button
    android:id="@+id/someButton"
    android:text="Do Something"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    local:MvxBind="Click SomeViewModelCommand" />
</LinearLayout>

Updated

SomeFragment.cs

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        // Use this to return your custom view for this Fragment
        // return inflater.Inflate(Resource.Layout.YourFragment, container, false);
        ShowHamburgerMenu = true;
        oldTitle = ((MainActivity)Activity).Title;
        ((MainActivity)Activity).Title = "Track Packages";
        //var view = base.OnCreateView(inflater, container, savedInstanceState);

        var ignored = base.OnCreateView(inflater, container, savedInstanceState);

        var view = this.BindingInflate(Resource.Layout.fragment_trackpackage, container, false);
        return view;
    }
Nick King
  • 190
  • 3
  • 20
  • I take it you have a *SomeView* that is a fragment? If so, did you make sure you called `this.BindingInflate(...)` in the *OnCreate()* method? See https://stackoverflow.com/questions/44184070/fragments-in-tablayout-do-not-bind-to-viewmodel/44184477#44184477 – Kiliman Jun 12 '17 at 20:36
  • ..@Kiliman I tried using `this.BindingInflate(...)` but it is still not working. – Nick King Jun 13 '17 at 17:18
  • Can you post some more code then? Also, did you look in your debug output? Mvx will log a warning if it can't find a valid binding. – Kiliman Jun 13 '17 at 17:25
  • Can you show where you inflate your view? – Cheesebaron Jun 14 '17 at 11:22
  • @Cheesebaron I have updated my question. – Nick King Jun 16 '17 at 13:10
  • This Fragment, how do you navigate to that? Or how do you assign the BindingContext for that? – Cheesebaron Jun 16 '17 at 13:12
  • @Cheesebaron I figured it out. But I have posted another question regarding MvxBind. Can you help? Thanks Link:- https://stackoverflow.com/questions/44659863/mvvmcross-mvxbind-not-bind-properly – Nick King Jun 20 '17 at 17:54

0 Answers0