DataTemplate.createContent() not successfully creating content?

LeloLelo Member ✭✭✭
edited May 31 in General

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

<ContentPage.Resources>
       <ResourceDictionary>
            <Label Text="I am label" x:Name="label" x:Key="label"/>
       </ResourceDictionary>
</ContentPaget.Resources>

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();
                stack.Children.Add(content);
            }
        }

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

Answers

  • 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.