我的 App.xaml
中不断出现奇怪的错误文件:
Element is already the child of another element.
我的 App.xaml 文件如下所示:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Celerior.Annapurna.SL.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ProvisiorResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
整个
ResourceDictionary
都报错了元素(从第 5 行到第 9 行)。ProvisiorResourceDictionary.xaml
包含许多样式和模板。在我看来没有什么令人兴奋的。有谁知道出了什么问题?
亲切的问候,
罗纳德·维尔登伯格
最佳答案
感谢 AnthonyWJones 在评论中提供的提示,我自己找到了问题的原因。
它出现在 Silverlight resource dictionary 中的所有内容必须是可共享的。原因是资源字典中的项目将(可能)添加到控制层次结构中的多个位置。
我的资源字典中有两个不可共享的项目。
编辑 : 在 WPF 中,您可以使用 x:Shared
资源字典中对象的属性,以强制 WPF 为每个资源检索创建一个新实例。不幸的是,Silverlight does not support这个属性。
关于silverlight - Silverlight App.xaml 中的“元素已经是另一个元素的子元素”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1727908/