Forum General

DataTemplate.createContent() not successfully creating content?

LeloLelo Member ✭✭✭
edited May 2019 in General

I have the following label just for testing in a ResourceDictionary in xaml of my ContentPage:

            <Label Text="I am label" x:Name="label" x:Key="label"/>

And I have this ClickedEventHandler on a button of the page in code behind:

void Handle_Clicked(object sender, System.EventArgs e)
            DataTemplate dataTemplate = new DataTemplate(() => label);
            for (int i = 0; i < 3; i ++)
                Label content = (Label) dataTemplate.CreateContent();

But only one label is added - to my StackLayout stack. Shouldn't three labels be added to it?


  • LeloLelo Member ✭✭✭

    I cloned label instead of using createContent(). And that worked. I asked this question on stackoverflow as well.

  • LeloLelo Member ✭✭✭

    This was meant to be posted in the Xamarin.Forms forum

Sign In or Register to comment.