【发布时间】:2014-03-09 22:57:40
【问题描述】:
我从来没有能够让这种格式的参考资源字典起作用。我错过了什么。
场景:
在其中创建和组装一些用户控件。
在根目录下说文件 {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 而言,这应该可以工作(据我所知),当我在设计器中时,它似乎很好(所有颜色都加载等)但是当我去编译我的应用程序和运行它我得到这个错误 {"Cannot locate resource 'themes/colorthemes.xaml'."} 这很奇怪,因为它似乎在构建器中使用得很好。所以我很困惑,因为它似乎与文档不一致。
所以如果有人可以向我解释我错过了什么:)
注意:如果我把之前的代码改成
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../../Themes/ColorThemes.xaml"/>
</ResourceDictionary.MergedDictionaries>
它工作正常,但是对于 cleanese pack://application: 。
【问题讨论】:
-
pack://application:,,,/YOURASSEMBLYNAME;component/Themes/ColorThemes.xaml 以确保。乌里 MSDN:msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx。在 Themes/Generic.xaml 中合并字典或 alle cc xaml 也很常见。我通常拆分我的抄送并称它们为 CcName.Generic.xaml。但这只是我的口味..
标签: .net wpf resourcedictionary