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

Bob Black picture Bob Black · Dec 3, 2010 · Viewed 16.5k times · Source

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.

Answer

kenwarner picture kenwarner · Dec 3, 2010

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>