且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将视图模型绑定到MVVMCROSS中的UserControl?

更新时间:2022-06-04 02:45:09

我最近一直在Windows Store中使用MVVMCross.不回头看我的代码,我很确定Datacontext将从其父级继承,除非被覆盖.

I've been using MVVMCross with Windows Store fairly recently. Without looking back at my code, I'm pretty sure that the Datacontext will inherit from it's parent unless overridden.

只要您提供的MvxPage具有视图模型,您在XAML或代码隐藏中添加到其中的任何用户控件都应共享相同的数据上下文.如果要从用户控件中进行一些MVVMCross数据绑定,则可能应该确保您的用户控件实现了IMvxStoreView,并确保将ViewModel属性设置为DataContext的值.

So as long as the MvxPage that you have presented has a viewmodel, any user control that you add to it, either in XAML or in code-behind, should share the same data context. If you are looking at doing some MVVMCross data-binding from the User Control, you should probably make sure your User Control implements IMvxStoreView, and ensure that the ViewModel property is set to the value of DataContext.

希望有帮助.

干杯, 特里斯坦