没有检测到安装的组件。元素已经是另一个元素的子 [英] No installed components were detected. Element is already the child of another element

查看:184
本文介绍了没有检测到安装的组件。元素已经是另一个元素的子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在App.xaml中我增加了应用程序资源的一个按钮为:

In App.xaml I have added Application Resources with a button as:

 <Application.Resources>
    <Button x:Key="MyButton"/>
</Application.Resources>

MainPage.xaml.cs中,我试图在我的编程网添加该按钮。

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:

未检测到安装的组件。元素已经是另一个元素的子

在MainPage.xaml中:

In MainPage.xaml:

 <Grid x:Name="myGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

</Grid>



我不知道我做错了。

I don't know what I'm doing wrong.

感谢。

推荐答案

如果您正在使用该控件的多个实例此异常通常是抛出您在应用程序的资源定义。如果是这样的话,你应该做的:

This exception is usually thrown if you're using more than one instance of the control you defined in your application resources. If that is the case, you should do:

<Button x:Key="MyButton" x:Shared="false"/>



编辑:看来WinRT的不支持X:。共享属性

it seems WInRT doesn't support x:shared attribute.

有使用是一个CONTROLTEMPLATES解决方法:的 http://www.gdomc.com/0428/binding-the-content-property-of-a-contentcontrol-in-winrt/

There is a workaround using ControlTemplates: http://www.gdomc.com/0428/binding-the-content-property-of-a-contentcontrol-in-winrt/

这篇关于没有检测到安装的组件。元素已经是另一个元素的子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆