I have an Activity in which fragments are placed in the layout. If I change the displayed fragment to another, the fragment will not be added to the rear stack, and therefore using the back button will immediately close the application instead of navigating back (FragmentManager.BackStackEntryCount is always 0 in OnBackPressed () -callback).
In the ViewModel "MainActivity" in which the fragments are placed, I display the fragment using 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 for assigning ViewModel 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 was expecting the "AddToBackstack" parameter or similar in the MvxFragment-Attribut or in the MvxFragment class, but there was nothing like that. Am I missing something or not back-stack support in the new fragmentator in MvvmCross 4.0?
source share