In App.xaml I have added Application Resources with a button as:
<Application.Resources>
<Button x:Key="MyButton"/>
</Application.Resources>
In MainPage.xaml.cs
, I tried to add this button programatically in my grid.
Button btn = (Button)Application.Current.Resources["MyButton"];
myGrid.Children.Add(btn);
But it gives error like this:
No installed components were detected. Element is already the child of another element.
In MainPage.xaml:
<Grid x:Name="myGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
</Grid>
I don't know what I'm doing wrong.
Thanks.