Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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: .

like image 696
Heinrich Avatar asked Mar 09 '14 22:03

Heinrich


2 Answers

try:

pack://application:,,,/YOURNAMESPACEHERE/ColorThemes.xaml

E.g.

pack://application:,,,/Themes/ColorThemes.xaml
like image 98
safetyOtter Avatar answered Sep 30 '22 23:09

safetyOtter


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.

like image 43
Athari Avatar answered Sep 30 '22 22:09

Athari