我被困在如何将 MvxBindableTableViewCell 的附件绑定(bind)到 bool 值上。
我将表的 ItemsSource 绑定(bind)到我的 ViewModel 中的列表,显示了一个不错的可点击项目列表。
但是我希望单元格的附件 (UITableViewCellAccessory.Checkmark) 仅在标记此对象时显示。标记是指模型中的 bool 值设置为真。
有谁知道如何绑定(bind)手机配件?
编辑: 我可以根据模型的 bool 值显示附件,但它没有绑定(bind)。
protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
{
UITableViewCell cell = tableView.DequeueReusableCell(CellIdentifier);
if (cell == null)
cell = new PlotsTableViewCell(UITableViewCellStyle.Subtitle, CellIdentifier);
Plot p = (Plot)item;
if (p.Done)
cell.Accessory = UITableViewCellAccessory.Checkmark;
return cell;
}
最佳答案
我认为您可以在 PlotsTableViewCell 中执行此操作。
如果您声明了一个自定义单元格,那么您可以在运行时在该单元格内进行绑定(bind)。
您可以在以下位置查看示例:https://github.com/slodge/MvvmCross/blob/vnext/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch/Cells/SessionCell2.cs在 session 显示中使用:
您可以看到单元格提供公共(public)属性,例如:
public string RoomText
{
get { return Label2.Text; }
set { if (Label2 != null) Label2.Text = value; }
}
然后提供绑定(bind)文本,如:
'RoomText':{'Path':'Item.Session','Converter':'SessionSmallDetails','ConverterParameter':'SmallDetailsFormat'},
要将附件绑定(bind)到 Bool,您应该能够执行以下操作:
public bool IsDone
{
get { return Accessory == UITableViewCellAccessory.Checkmark; }
set
{
if (value)
{
Accessory = UITableViewCellAccessory.Checkmark;
}
else
{
Accessory = UITableViewCellAccessory.None;
}
}
}
带文字:
'IsDone':{'Path':'Done'},
作为一种高级技术,您还可以在自定义绘制的按钮内使用自定义图像,而不是在您的单元格中使用附件。要了解如何执行此操作,请查看 IsFavorite
属性如何在该 session 示例中绑定(bind) - 请参阅 https://github.com/slodge/MvvmCross/tree/vnext/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch/Bindings 中的两种自定义绑定(bind)方式
关于uitableview - 将 MvxBindableTableViewCell 的附件绑定(bind)到 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13974166/