3

I have a resource file and two views. This views use a resource file

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

And it will work while i dont put one view to the another. In this case i get this error

Cannot locate resource 'dictionary1.xaml'

How to fix it?

Nodon
  • 967
  • 11
  • 24

2 Answers2

10

Use Pack Uri's

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Assembly_Name;component/Dictionary1.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
Amol Bavannavar
  • 2,062
  • 2
  • 15
  • 36
  • 1
    this is the only thing that worked for me, yet Microsoft doesn't list it in examples. Regular paths would work fine the application, but design mode and the IDE complain with errors. – Michael Brown Jun 08 '20 at 19:48
4

If Dictionary1.xaml in your project's rootpath, remove '/' before Dictionary1

<ResourceDictionary Source="Dictionary1.xaml"/>

Or you can use packuri like :

 /yourAssemblyName;component/Dictionary1.xaml
mhDuke
  • 137
  • 1
  • 10
Rang
  • 1,362
  • 7
  • 17
  • 30
  • To be precise, it's the _assembly name_, not the _namespace_ and the leading forward slash seems optional... – Cool Blue Dec 16 '16 at 03:58
  • This is still the case in VS2015. I got an error about a user control not finding a resource dictionary file in my project root folder, when I named it with a leading forward slash `/resourcedictionary.xaml`. Why does this cause error messages, considering that it runs fine? – Oystein Jan 30 '18 at 08:29