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

How to set ItemTemplate to StackLayout?

$
0
0

How can I set an ItemTemplate to a StackLayout? It works fine for a simpler variation using only TextCell. With StackLayout, it throws an exception. I think the issue is Databinding. I'm unsure of how to do it.

        ListView L = new ListView()
        {
            ItemsSource = { some legit stuff that's working fine },
            ItemTemplate = new DataTemplate(() => new A()) // works fine for TextCell but not StackLayout
        };


class A : StackLayout
{
    public A()
    {
        Label labelName = new Label();
        labelName.SetBinding(Label.TextProperty, "Name");
        Label labelDescription = new Label();
        labelDescription.SetBinding(Label.TextProperty, "Description");
        Children.Add(labelName);
        Children.Add(labelDescription);
    }
}

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>