Xamarin mvmcross tab navigation between view model

2019-09-12 22:17发布

问题:

I have two screens which are linked to two tab buttons

  1. Name
  2. Duration

I would like tab to move to second button when I click Next button. In my view model this is my command for Next Button

Here is my code sample

public IMvxCommand NextCommand
{
    get
    {
        return new MvxCommand(() => ShowViewModel<RecyclerViewModel>());
    }
}

Rather than tab moving to next tab second view is opening in full screen.

Screens attached

First screen

Second screen

Screen I am seeing

回答1:

I this situation i would not use the MvvmCross ViewModel navigation, because to use that you probably have to create a custom presenter.

What you can do is just add a button click in the Activity or Fragment itself and use the following code:

var viewPager = view.FindViewById<ViewPager>(Resource.Id.viewpager);
viewPager.SetCurrentItem(1, true);