I'm new to MVVMCross, theoretically it's shouldn't be that hard until I started using UICollectionViewCell
I have multiple sections in my view controller, and each of them should bind to different types of data, what should I do?
in the ViewModel, it has a list and a property I want to use the following properties to fill my custom cells
List<ClassForCell1> list;
private int _valueForCell2;
public int ValueForCell2
{
get => _valueForCell2;
set => _valueForCell2 = value;
}
In MySource class, I registered different types of Cell, which looks like this
public MySource(UICollectionView collectionView, ViewModel viewModel) : base(collectionView)
{
_viewModel = viewModel;
collectionView.RegisterClassForCell(typeof(CustomCell1), CustomCell1.Key);
collectionView.RegisterNibForCell(CustomCell2.Nib, CustomCell2.Key);
//... some other cell registration
}
Here are my Cells
protected CustomCell1(IntPtr handle) : base(handle)
{
this.DelayBind(() =>
{
var set = this.CreateBindingSet<CustomCell1, ClassForCell1>();
set.Bind(NameLabel).To(m => m.name);
set.Apply();
});
}
protected CustomCell2(IntPtr handle) : base(handle)
{
this.DelayBind(() =>
{
// how to bind this one?
var set = this.CreateBindingSet<CustomCell2, ???>();
set.Bind(NameLabel).To(a view model's value); // ValueForCell2 in ViewModel
set.Apply();
});
}
My questions are:
- How can I bind viewModel's specific property or list to the specific cell(s) or section(s)?
here's the code snippet in my ViewController, in order to bind ViewController and ViewModel, and it seems like doesn't work at all
var source = new MySource(MyCollectionView, MyViewModel);
var set = this.CreateBindingSet<MyViewController, MyViewModel>();
- For CustomCell2, how to bind a label's Text property to view model's property? (ValueForCell2)