How to add a fragment to the backstack in MvvmCross 4.0?

Viewed 1600

I have an Activity which hosts fragments in a frame-layout. If I change the displayed fragment to another, the fragment isn't added to the back-stack and therefore the use of the "Back"-button will immeditately close the app instead of navigating back (FragmentManager.BackStackEntryCount is always 0 in the OnBackPressed()-callback).

In the ViewModel of the "MainActivity" that hosts the fragments I show the fragment via the ShowViewModel<>-method:

public class MainViewModel : MvxViewModel
{
    public IMvxCommand ShowHomeCommand
    {
        get { return new MvxCommand(ShowHomeExecuted); }
    }

    private void ShowHomeExecuted()
    {
        ShowViewModel<HomeViewModel>();
    }
}

The fragment-class has an annotation to assign the ViewModel to a host-activity:

[MvxFragment(typeof(MainViewModel), Resource.Id.fragment_container)]
[Register("namespace.of.HomeFragment")]

I use the default AndroidViewPresenter in my Setup-class:

protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
   var mvxFragmentsPresenter = new MvxFragmentsPresenter(AndroidViewAssemblies);
   Mvx.RegisterSingleton<IMvxAndroidViewPresenter>(mvxFragmentsPresenter);
   return mvxFragmentsPresenter;
}

I expected a parameter "AddToBackstack" or similar in the MvxFragment-Attribut or in the MvxFragment-class but there is nothing like this. Do I miss something or is there currently no support for the back-stack in the new fragment-mechanism in MvvmCross 4.0?

2 Answers
Related