I have a CustomViewCell with controls that are bound to my model object -- that works fine. What I'm trying to do now is add a bindable ListItemType property to my CustomViewCell so I can display multiple kinds of cells in one ListView. Here is my code:
public enum ListItemType
{
Header = 0,
Data = 1
}
In my CustomViewCell I add the BindableProperty:
public static readonly BindableProperty ListItemTypeProperty =
BindableProperty.Create<CustomViewCell,ListItemType> (
p => p.ListItemType, ListItemType.Header);
public ListItemType ListItemType
{
get { return (ListItemType)GetValue(ListItemTypeProperty); }
set { SetValue(ListItemTypeProperty, value); }
}
And in the constructor I set the binding:
public CustomViewCell()
{
SetBinding(CustomViewCell.ListItemTypeProperty, new Binding("Type"));
...
}
The binding isn't working though. If I set a breakpoint on ListItemType property it never reaches it. As a test, I created a binding on a Label control like so, and the ListItemType would display correctly meaning the first cell would display Header and the remaining cells display Data.
var typeLabel = new Label();
typeLabel.SetBinding(Label.TextProperty, new Binding("Type"));
How can I properly set up a binding to a property within my ViewCell?