我有一个使用MvxTabsFragmentActivity的选项卡式应用程序。 当我在选项卡之间导航时,行为是正确的,但是当我第一次尝试在片段内导航时,不会替换被调用的片段。
我尝试使用IMvxNavigationService和经典方法(使用ShowViewModel),但是它们的作用相同。
我还使用了一个自定义演示器来显示片段,但是无论有没有片段,问题依旧。
打印屏幕上有图像 https://imgur.com/a/cfRWlsl
突出显示的红色是我要导航到的片段,黑色的是上一个片段。
这是具有导航所需按钮的视图:
public class TrackView : MvxFragment<TrackViewModel>
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.track_layout, null);
var nextButton = view.FindViewById<Button>(Resource.Id.navigate);
var set = this.CreateBindingSet<TrackView, TrackViewModel>();
set.Bind(nextButton).To(vm => vm.NavigateEventCommand);
set.Apply();
return view;
}
}
这是它的ViewModel:
public class TrackViewModel : MvxViewModel
{
private readonly IMvxNavigationService _navigationService;
public TrackViewModel(IMvxNavigationService navigationService)
{
this._navigationService = navigationService;
}
public IMvxCommand NavigateEventCommand => new MvxAsyncCommand(NavigateCommand);
private async Task NavigateCommand()
{
await _navigationService.Navigate<RegistrationViewModel>();
}
}
这是我要导航到的视图:
public class RegistrationView : MvxFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.registration_layout, null);
//var set = this.CreateBindingSet<RegistrationView, RegistrationViewModel>();
//set.Apply();
return view;
}
}
这是它的ViewModel:
public class RegistrationViewModel : MvxViewModel
{
}
我还有一个使用MvxTabsFragmentActivity的选项卡式应用程序,我正在创建如下选项卡:
protected override void AddTabs(Bundle args)
{
this.AddTab<TrackView>(
args,
Mvx.IocConstruct<TrackViewModel>(),
this.CreateTabFor("0", Resource.Drawable.ic_track, "Track"));
this.AddTab<SendView>(
args,
new SendViewModel(),
this.CreateTabFor("1", Resource.Drawable.ic_send, "Send"));
this.AddTab<ProfileView>(
args,
new ProfileViewModel(),
this.CreateTabFor("2", Resource.Drawable.ic_profile, "Profile"));
this.AddTab<MoreView>(
args,
new MoreViewModel(),
this.CreateTabFor("3", Resource.Drawable.ic_more, "More"));
}
我有一个自定义演示者,该演示者在主类中是以这种方式注册的:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.tabHost = this.FindViewById<TabHost>(Android.Resource.Id.TabHost);
presenter = (DroidPresenter)Mvx.Resolve<IMvxAndroidViewPresenter>();
var initialFragment = new TrackView() { ViewModel = Mvx.IocConstruct<TrackViewModel>() };
presenter.RegisterFragmentManager(FragmentManager, initialFragment);
}
正如我说的,无论有没有主持人,行为都是相同的。
我正在使用MvvmCross 5.7。