Ale*_*akh 2 data-binding mvvm ios mvvmcross xamarin
我已经创建了表源,并希望不将它绑定到当前数据上下文,而是绑定到由Controller动态创建的另一个ViewModel.
//some button click
var context = new DynamicViewModel();
var source = new MyTableViewSource();
source.ItemsSource = context.DataItems; //I want this line to work with bindings
在View端,Mvx绑定IMvxBindingContextOwner可以直接用于ViewModel- 这允许它们在整个ViewModel更改时更新.
因此,要执行您想要执行的操作,您需要提供一个将IMvxBindingContextOwner其动态视图模型保存在其BindingContext中的当前DataContext中.
要做到这一点,尝试创建一个虚拟所有者,如:
 public class MyOwner : IMvxBindingContextOwner 
 { 
     public MyOwner() { BindingContext = new MvxBindingContext(); {
     public IMvxBindingContext BindingContext { get; private set; } 
 } 
然后,您应该能够将其用作新绑定集的目标 - 例如
 _owner = new MyOwner();
 _owner.BindingContext.DataContext = dynamicViewModel;
 var set = _owner.CreateBindingSet<MyOwner, DynamicViewModel>(); 
 // set.Bind statements
 set.Apply(); 
没有测试......但是应该工作......如果遇到问题,那么还要考虑使用现成的MvxView控制 - 这是一个BindingContextOwner你可以设置它DataContext
| 归档时间: | 
 | 
| 查看次数: | 1482 次 | 
| 最近记录: |