Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How can I access the ItemsSource/Model directly in my custom ViewCell?

$
0
0

Sorry if this a obvious, but I'm not sure how to accomplish the following:

Simple model:

public class Person
{
        public string Name { get; set; }
        public List<DateTime> Lockouts { get; set; }
}

Generating a page with a list view with a custom item template:

var view = new ListView ();
view.ItemsSource = Context.DataSource.People;       //this is a List<Person> object
view.ItemTemplate = new DataTemplate(typeof(LockoutListCell));

Inside my custom ViewCell:

public class LockoutListCell : ViewCell
{
        public LockoutListCell ()
        {
                //I can bind a label with the person instance
                var label = new Label { VerticalOptions = LayoutOptions.Center };
                label.SetBinding<Person> (Label.TextProperty, p => p.Name)

                //but I want to access the Lockouts DateTime list to perform logic (number of items in the list, last date in the list, etc)
                OBJECT_WHERE_CAN_I_ACCESS.Lockouts
        }
}

Hope that makes sense :)
Thanks in advance


Viewing all articles
Browse latest Browse all 58056

Trending Articles