【发布时间】:2018-09-10 21:37:16
【问题描述】:
有没有办法从我的当前视图而不是根视图导航到 ViewModel?
我创建了一个从根视图模态呈现的视图模型,并希望在该视图中呈现一个视图模型。
例如,当从我的模态视图调用_navigationService.Navigate<MyViewModel>(); 时,根视图导航到 MyViewModel 而不是当前的模态视图。这会使我的模态屏幕留下一个空白页面,直到您将其关闭并看到导航已发生在下方。
我要创建自定义导航,还是有更好的方法?
编辑
这里有一些代码:
我的视图模型
public class ViewModel1 : MvxViewModel
{
private readonly IMvxNavigationService _navigationService;
public ViewModel1(IMvxNavigationService navigationService)
{
_navigationService = navigationService;
}
public IMvxCommand NavigateCommand => new MvxCommand(ChangeView);
void ChangeView()
{
_navigationService.Navigate<ViewModel2>();
}
}
我的观点
[MvxModalPresentation(WrapInNavigationController = true, ModalPresentationStyle = UIModalPresentationStyle.Custom, Animated = false)]
public partial class MyView : MvxViewController
{
ViewModel1 VM;
public MyView() : base("MyView", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
NavigationController.NavigationBar.Hidden = true;
var set = this.CreateBindingSet<MyView, ViewModel1 >();
set.Bind(NextButton).To(vm => vm.NavigateCommand);
set.Apply();
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
我想让导航命令在呈现的模式中呈现 ViewModel2。
【问题讨论】:
-
你能展示你的代码吗?
-
添加了一些代码:)