Loading Resource Dictionaries

If you create a customizable application you’ll most likely use Resource Dictionaries, you can choose to have the default application style inside the application assembly to preserve the look you envisioned for that application and as a fail-safe. Today we’ll see how to load a Resource Dictionary, both from the application assembly and from the file system.

Application.Current.Resources = (ResourceDictionary)Application.LoadComponent(

                    new Uri(string.Format(“themes\\{0}\\{0}.xaml”, theme), UriKind.Relative));

This sample code works both for the assembly stored Resource Dictionary as well as for the File System. The LoadComponent() Method returns an Object, that object is the root element of the loaded XAML, so, you could have any type of XAML element and load it anytime during the application execution. This trick is useful for a themes implementation, loading XAML vectors or even custom animations.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: