pack://application:,,,/ResourceFile.xaml Never Works

ⅰ亾dé卋堺 提交于 2019-12-09 11:48:02

问题


I have never been able to get this format of reference a Resource Dictionary to work. What am I missing.

Scenario:

Creating and assembly with some usercontrols in it.
At root have said file {root}/Themes/ColorThemes.xaml
The ColorThemes.xaml file has its build action set to Resource.
Then in in xaml file further down let say {root}/Controls/ButtonStyles/Themes/ButtonThemes.xaml (note the path is just an example) in this file I have the following bit of code:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/Themes/ColorThemes.xaml"/>
</ResourceDictionary.MergedDictionaries>

As far as the documentation states this should work (as I understand it), and while I am in the designer it seems to be fine (all the colors load etc) however when I then go and compile my application and run it I get this error {"Cannot locate resource 'themes/colorthemes.xaml'."} which is strange because it seemed to be using just fine in the builder. So I am quiet confused because it seems to not coincide with the documentation.
So if someone can explain to me what I am missing :)

Note: if I change the previous code to

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../../../Themes/ColorThemes.xaml"/>
</ResourceDictionary.MergedDictionaries>

It works fine, however for cleanese pack://application: .


回答1:


try:

pack://application:,,,/YOURNAMESPACEHERE;component/Themes/ColorThemes.xaml



回答2:


Can't reproduce your problem. All these variations work fine:

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/Themes/ColorThemes.xaml"/>
    <ResourceDictionary Source="/Themes/ColorThemes.xaml"/>
    <ResourceDictionary Source="../../Themes/ColorThemes.xaml"/>
</ResourceDictionary.MergedDictionaries>

Note that pack://application:,,, is optional and / refers to the root of the current assembly.

Please provide complete minimal example which reproduces your problem.



来源:https://stackoverflow.com/questions/22289367/pack-application-resourcefile-xaml-never-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!