Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a ResourceDictionary defined in a subfolder to App.xaml?

All of the code samples I've found so far reference a Resource Dictionary that's not in a project subfolder (the dictionary is at the root of the project). I have mine in a subfolder, and I can't figure out how to get WPF to find it. This doesn't work...

<Application.Resources>
     <ResourceDictionary Source="/Skins/Black/GlossyButtons.xaml"/>
</Application.Resources>

The ASP.Net tilde syntax doesn't seem to work either.

Is this the best way to include a ResourceDictionary in your app so that WPF can find resources? My goal in this particular case is to apply a style defined in GlossyButtons.xaml to all of the buttons in my app.

like image 616
Bob Black Avatar asked Dec 03 '10 20:12

Bob Black


2 Answers

Try the Pack URI syntax

http://msdn.microsoft.com/en-us/library/aa970069.aspx

<Application.Resources>
     <ResourceDictionary Source="pack://application:,,,/Skins/Black/GlossyButtons.xaml"/>
</Application.Resources>
like image 63
kenwarner Avatar answered Sep 18 '22 14:09

kenwarner


Discovered the problem - WPF couldn't find an assembly referenced in GlossyButtons.xaml, but didn't show the actual error (that there was a problem with the .xaml) until I had compiled and executed several times. The error displayed (at first) was that GlossyButtons.xaml couldn't be located.

That was a little confusing.

like image 28
Bob Black Avatar answered Sep 21 '22 14:09

Bob Black