WPF资源 - 如果属性使用显式集合标记,则该属性只能有一个子元素

时间:2014-04-16 16:56:46

标签: wpf xaml user-controls resourcedictionary

我正在尝试将资源字典添加到用户控件,如下所示:

用户控制查看/ AllOrdersView.xaml

UserControl

资源字典查看/ AllOrdersViewResources.xaml

ResourceDictionary

Solution Explorer 显示UserControl和ResourceDictionary

SolutionExplorer

错误消息

  

无法向属性“资源”添加元素,因为属性可以   如果它使用显式集合标记,则只有一个子元素。

疑难解答步骤

1 个答案:

答案 0 :(得分:4)

你的XAML错了。这是合并ResourceDictionaries的正确方法:

<UserControl.Resources>
    <ResourceDictionary>
       <ResourceDictionary.MergedDictionaries>
           <ResourceDictionary Source="AllOrdersViewResources.xaml"/>
       </ResourceDictionary.MergedDictionaries>

       <!-- More resources here -->
    </ResourceDictionary>
</UserControl.Resources>