我从来没有能够使这种格式的引用资源字典工作。我错过了什么
场景:
在其中创建和组装一些用户控件。 在root上有文件{root} /Themes/ColorThemes.xaml ColorThemes.xaml文件的构建操作设置为Resource。 然后在xaml文件中进一步向下说出{root} /Controls/ButtonStyles/Themes/ButtonThemes.xaml(注意路径只是一个例子)在这个文件中我有以下代码:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Themes/ColorThemes.xaml"/>
</ResourceDictionary.MergedDictionaries>
至于documentation状态这应该工作(据我所知),虽然我在设计师看起来很好(所有颜色加载等)然而当我然后去编译我的应用程序并运行它我得到这个错误{“无法找到资源'themes / colorthemes.xaml'。”}这很奇怪,因为它似乎在构建器中使用得很好。所以我很安静,因为它似乎与文档不一致。 所以如果有人能向我解释我错过了什么:)
注意:如果我将以前的代码更改为
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../../Themes/ColorThemes.xaml"/>
</ResourceDictionary.MergedDictionaries>
它工作正常,但对于cleanese pack://应用程序:。
尝试:
pack://application:,,,/YOURNAMESPACEHERE;component/Themes/ColorThemes.xaml
无法重现您的问题。所有这些变化都很好:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Themes/ColorThemes.xaml"/>
<ResourceDictionary Source="/Themes/ColorThemes.xaml"/>
<ResourceDictionary Source="../../Themes/ColorThemes.xaml"/>
</ResourceDictionary.MergedDictionaries>
请注意,pack://application:,,,
是可选的,/
是指当前程序集的根。
请提供完整的最小示例,以再现您的问题。