silverlight - Silverlight App.xaml 中的“元素已经是另一个元素的子元素”错误

标签 silverlight xaml silverlight-3.0

我的 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/

相关文章:

c# - MSDN 代码示例中缺少空格和换行符

wpf - 如何使 ItemsControl 拉伸(stretch)以填充所有可用空间?

Silverlight MVVM Prism 和 OpenFileDialog

silverlight-3.0 - Silverlight DataGrid 从代码更新 SelectedItem

银光 PDF 查看器

c# - 更改图像源属性时崩溃

silverlight - Silverlight测试框架的EnqueueConditional是如何工作的?

silverlight - 无论如何要更改 Silverlight 3 中 OpenFileDialog 的标题?

Silverlight 和整体字体大小

c# - 如何使用 Expression (C#) 引发父类事件