Sunday, January 13, 2013

WPF Resource Dictionary


Provides a hash table / dictionary implementation that contains WPF resources used by components and other elements of a WPF application. 

Adding a source for the resource dictionary will command the run time engine to load external resources into the current XAML file executed. Below are the example how to add the external resources.

Link to ResourceDictionary

MergeDictionaries Property

Gets a collection of the ResourceDictionary dictionaries that constitute the various resource dictionaries in the merged dictionaries.

Link to MergeDictionaries

Adding Resources inside ResoureDictionary

In FrameworkElement.Resources property, you can add only a single resource ResourceDictionary object by providing the Source property with the relative path of your Resource XAML file (within the solution). If you're adding a multiple resource object, then in the FrameworkElement.Resources property, you need to fill the MergeDictionaries property of the FrameworkElement with the list of ResourceDictionary object. Below is the sample how to reference multiple resources.

Referencing to other Assembly

Referencing ResourceDictionary to other assembly is not that a big deal. You only need to enclose the proper application name (assembly name and the path of the resource inside that assembly). Below is the example of how to do it.

You will notice squibbly lines above if you have referenced to a wrong file inside that assembly. Please be aware of that.

Note: Please ensure that you set the Build Action to Resource to make the referencing works.

No comments:

Post a Comment

Place your comments and ideas