将ViewModel命令绑定到MvxCollectionViewCell

时间:2017-12-02 07:41:37

标签: mvvmcross

我正在研究iOS AppStore的MvvxCross克隆

enter image description here

我希望将单个应用程序单元格的单击绑定到我的ViewModel命令。

是否有人可以向我指出代码示例如何实现?

以下是克隆应用的源代码 https://github.com/L3xer/MvvmCross-AppStore

1 个答案:

答案 0 :(得分:0)

好吧,你要我完全编码,而不是它是如何工作的,你应该向我们展示你的尝试。

我很确定slodge有一个关于你在他的N + 1系列中面临的场景的博客。

无论如何这里有一些线索。

在你看来(控制器)。

var source = new MyCustomSource(this, ViewModel, tableView);
      
MycollectionView.Source = source;
    
var set = this.CreateBindingSet<MyView, MyViewModel>();
     
set.Bind(source).To(vm => vm.Cards); 
set.Apply();

在MyCustomSource中,你将使用你的UICollectionViewCell。

在Cell类中,你需要在构造函数中使用它。

this.DelayBind(() =>
      {
     
var set = this.CreateBindingSet<MyCell, MyModel>();
     
set.Bind(Primary_Btn).To(vm => vm.ShowL2CardDetail);
       
set.Bind(Secondary_Btn).To(vm => vm.ShowL2ExternalCardDetail);
                    set.Apply();
      
});