你如何正确地子类化 MvxCollectionViewSource?
How do you properly subclass MvxCollectionViewSource?
实现自定义 MvxCollectionViewSource
的技巧是什么?
我已经将它子类化并为 GetCell()
提供了一个实现,但是生成的单元格不是数据绑定的。当我使用开箱即用的 MvxCollectionViewSource
时,它起作用了。
这是一个 101 用例,所以我一定是做错了什么。我正在使用 MvvmCross 5.7。任何帮助,将不胜感激?
GetCell
in MvxCollectionViewSource
, MvxTableViewSource
和其他变体在那里进行绑定。因此,如果您覆盖该方法,您将负责进行绑定。
如果您只是想提供自己的 Cell,则应改写 GetOrCreateCellFor
。此方法在 GetCell
中用于获取实际单元格并将其绑定到通过调用 GetItemAt
.
找到的项目
所以改写 GetOrCreateCellFor
:
protected override UICollectionViewCell GetOrCreateCellFor(
UICollectionView collectionView, NSIndexPath indexPath, object item)
{
var cell = collectionView.DequeueReusableCell(MyCustomCell.Identifier, indexPath) as MyCustomCell;
if (cell == null)
cell = new MyCustomCell();
return cell;
}
实现自定义 MvxCollectionViewSource
的技巧是什么?
我已经将它子类化并为 GetCell()
提供了一个实现,但是生成的单元格不是数据绑定的。当我使用开箱即用的 MvxCollectionViewSource
时,它起作用了。
这是一个 101 用例,所以我一定是做错了什么。我正在使用 MvvmCross 5.7。任何帮助,将不胜感激?
GetCell
in MvxCollectionViewSource
, MvxTableViewSource
和其他变体在那里进行绑定。因此,如果您覆盖该方法,您将负责进行绑定。
如果您只是想提供自己的 Cell,则应改写 GetOrCreateCellFor
。此方法在 GetCell
中用于获取实际单元格并将其绑定到通过调用 GetItemAt
.
所以改写 GetOrCreateCellFor
:
protected override UICollectionViewCell GetOrCreateCellFor(
UICollectionView collectionView, NSIndexPath indexPath, object item)
{
var cell = collectionView.DequeueReusableCell(MyCustomCell.Identifier, indexPath) as MyCustomCell;
if (cell == null)
cell = new MyCustomCell();
return cell;
}