Kis*_*Oli 8 c# windows xaml windows-runtime windows-8.1
在 App.xaml 中,我添加了带有按钮的应用程序资源:
<Application.Resources>
<Button x:Key="MyButton"/>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
在 中MainPage.xaml.cs
,我尝试以编程方式在我的网格中添加此按钮。
Button btn = (Button)Application.Current.Resources["MyButton"];
myGrid.Children.Add(btn);
Run Code Online (Sandbox Code Playgroud)
但它给出了这样的错误:
No installed components were detected. Element is already the child of another element.
在 MainPage.xaml 中:
<Grid x:Name="myGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
</Grid>
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么。
谢谢。