I have the following label 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 in in my code behind I have this clicked event handler:
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);
}
}
In my StackLayout called stack - only 1 label is added when the button assigned with Handle_Clicked is pressed. Why is only 1 label added - when there should be 3 labels added?