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

BInding a listview to a property in a List

$
0
0

Hi,

I have a class that is used to grab data from an SQLite query. The class looks something like this

class DataClass 
{
    public string Name {get;set;}
    public string id {get;set;}
}

I grab my data from the database which creates a List<DataClass> object. Once this object has been created, next comes the list view which is where the problems start. Currently, it looks like this

var publist = new ListView
{
        ItemsSource = pubgroups,
        IsGroupingEnabled = true,
        GroupDisplayBinding = new Binding("Public"),
        ItemTemplate = new DataTemplate(() =>
         {
                 var label = new Label()
                 {
                         Text = SetBinding(TextCell.TextProperty, "Name" ),
                          ClassId = SetBinding(ClassIdProperty, "id")
                 };
                 var image = new Image()
                 {
                         ClassId = SetBinding(ClassIdProperty, "id"),
                         Source = Device.OS == TargetPlatform.WinPhone ? "Images/groups" : "groups",
                         WidthRequest = 50,
                         HeightRequest = 50,
                 };

The issues come with the SetBindings - the compiler is telling me that I can't bind to "Name" or "id"

Is there a way to bind the properties within the label and image directly to the properties within the List or do I have to perform some intermediate step?

Paul


Viewing all articles
Browse latest Browse all 58056

Trending Articles