将MvxBindableTableViewCell的附件绑定到布尔值 [英] Bind MvxBindableTableViewCell's Accessory to boolean
问题描述
我坚持如何将MvxBindableTableViewCell的附件绑定到布尔值.
I'm stuck on how to bind the MvxBindableTableViewCell's accessory to a boolean.
我将表的ItemsSource绑定到了我的ViewModel中的一个列表,显示了一个不错的可单击项列表.
I have the table's ItemsSource bound to a list in my ViewModel, showing a nice list of clickable items.
但是,我希望仅在标记此对象时才显示单元格的附件(UITableViewCellAccessory.Checkmark).通过标记,我的意思是模型中的布尔值设置为true.
However I want the cell's accessory (UITableViewCellAccessory.Checkmark) to show only when this object is flagged. By flagged I mean a boolean in the model is set to true.
有人知道如何绑定单元的附件吗?
Does anyone know how to bind the cell's accessory?
我可以根据模型的布尔值来显示附件,但它没有绑定.
I can show the Accessory depending on the model's boolean, but it's not bound.
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中进行此操作.
I think you can probably do this in your PlotsTableViewCell.
如果声明自定义单元格,则可以在运行时在该单元格中进行绑定.
If you declare a custom cell, then you can bind within that cell at runtime.
You can see an example of this in: https://github.com/slodge/MvvmCross/blob/vnext/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch/Cells/SessionCell2.cs which is used in the sessions display:
您可以看到该单元格提供了以下公共属性:
You can see that the cell provides public properties like:
public string RoomText
{
get { return Label2.Text; }
set { if (Label2 != null) Label2.Text = value; }
}
,然后提供类似以下内容的绑定文本:
and then provides binding text like:
'RoomText':{'Path':'Item.Session','Converter':'SessionSmallDetails','ConverterParameter':'SmallDetailsFormat'},
要将附件绑定到Bool,您应该可以执行以下操作:
For binding an Accessory to a Bool, you should be able to do something like:
public bool IsDone
{
get { return Accessory == UITableViewCellAccessory.Checkmark; }
set
{
if (value)
{
Accessory = UITableViewCellAccessory.Checkmark;
}
else
{
Accessory = UITableViewCellAccessory.None;
}
}
}
含文字:
'IsDone':{'Path':'Done'},
作为一种高级技术,您还可以在自定义绘制按钮内使用自定义图像,而不是在单元格中使用附件.要查看如何执行此操作,请查看该会议示例中如何绑定IsFavorite
属性-请参见
As an advanced technique, you could also use a custom image inside a custom drawn button instead of an Accessory in your cell. To see how to do this, take a look at how the IsFavorite
property is bound in that conference sample - see the two way custom bindings in https://github.com/slodge/MvvmCross/tree/vnext/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch/Bindings
这篇关于将MvxBindableTableViewCell的附件绑定到布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!