Xamarin.ios 使用MVVMCross绑定到ViewController中的视图

Xamarin.ios 使用MVVMCross绑定到ViewController中的视图,xamarin.ios,mvvmcross,Xamarin.ios,Mvvmcross,所以我一直在搜索网络,但是随着MVVMCross的更新,我想不出怎么做 对我来说,我可以做到以下几点: MvxFluentBindingDescriptionSet<PageOneView, PageOneViewModel> set = this.CreateBindingSet<PageOneView, PageOneViewModel>(); set.Bind(_HearingLossPickerView).To(vm => vm.HearingLoss);

所以我一直在搜索网络,但是随着MVVMCross的更新,我想不出怎么做

对我来说,我可以做到以下几点:

MvxFluentBindingDescriptionSet<PageOneView, PageOneViewModel> set = this.CreateBindingSet<PageOneView, PageOneViewModel>();
set.Bind(_HearingLossPickerView).To(vm => vm.HearingLoss);
set.Apply();
MvxFluentBindingDescriptionSet=this.CreateBindingSet();
set.Bind(_HearingLossPickerView).To(vm=>vm.HearingLoss);
set.Apply();
但是,这将创建我的viewmodel的新实例。我希望能够使用现有的viewmodel。我试着只设置DataContext,但没有骰子

因此,我的流程基本上如下所示。
视图控制器(PagesViewController)->视图(PageOneView)
MainViewModel(PagesViewModel)->子视图模型(PageOneViewModel)

我能够像使用集合一样创建
PagesViewModel
,我希望基本上将
PageOneViewModel
PagesViewModel
传递到
PageOneView


非常基本的东西,所以如果有人可以帮助你,那就是Amazoballs。

MvvmCross允许你覆盖视图模型位置-请参阅中的部分和示例代码

此外,您还可以直接在视图代码中设置ViewModel-只需确保在MvvmCross执行ViewModel位置的
base.viewdiload
之前执行此操作



请注意,依赖于预先创建的ViewModels的基本模式在Android和WindowsPhone等环境中可能会出现问题,在这些环境中,逻辑删除意味着您的应用程序可以在任何活动或页面上关闭和重新启动。

Stuart的回答相当可靠。好东西,伙计。但是在看了N+1系列中的一些视频后,我发现我需要做的是延迟绑定

所以对于其他被困的人,请退房

例如

我的孩子视图模型
this.DelayBind(()=>
{
MvxFluentBindingDescriptionSet=this.CreateBindingSet();
set.Bind(SubmitButton).To(v=>v.NextCommand);
set.Apply();
});
我的父视图模型
MvxFluentBindingDescriptionSet=this.CreateBindingSet();
set.Bind(SomePage).For(p=>p.DataContext).To(v=>v.SomeViewModel);
this.DelayBind(() =>
{
    MvxFluentBindingDescriptionSet<SomeView, SomeViewModel> set = this.CreateBindingSet<SomeView, SomeViewModel>();
    set.Bind(SubmitButton).To(v => v.NextCommand);
    set.Apply();
});
MvxFluentBindingDescriptionSet<ViewController, ViewControllerViewModel> set = this.CreateBindingSet<ViewController, ViewControllerViewModel>();
set.Bind(SomePage).For(p => p.DataContext).To(v => v.SomeViewModel);