在UserControl库中使用全局ResourceDictionary

时间:2011-02-28 16:09:23

标签: c# wpf user-controls global resourcedictionary

我在“App.xaml”中有“Project A”和“MyResourceDictionary.xaml”

<Application.Resources>

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="MyResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

</Application.Resources>

我想在我的用户控件库中使用“MyResourceDictionary.xaml” - “Project B”

我可以这样做吗?

谢谢, 埃蒙

2 个答案:

答案 0 :(得分:2)

查看pack URI syntax。类似的东西:

<ResourceDictionary Source="ProjectB;component/MyResourceDictionary"/>

答案 1 :(得分:2)

@Kent Boogaart

感谢Kent的帮助,这是工作代码

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/ProjectA;component/MyResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

其他任何有问题的人都查看此链接 - http://msdn.microsoft.com/en-us/library/aa970069.aspx

谢谢, 埃蒙