【发布时间】:2023-03-19 00:59:01
【问题描述】:
在 App.xaml 中,我添加了带有按钮的应用程序资源:
<Application.Resources>
<Button x:Key="MyButton"/>
</Application.Resources>
在MainPage.xaml.cs 中,我尝试以编程方式将这个按钮添加到我的网格中。
Button btn = (Button)Application.Current.Resources["MyButton"];
myGrid.Children.Add(btn);
但它给出了这样的错误:
No installed components were detected. Element is already the child of another element.
在 MainPage.xaml 中:
<Grid x:Name="myGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
</Grid>
我不知道我做错了什么。
谢谢。
【问题讨论】:
标签: c# windows xaml windows-runtime windows-8.1