#53 – Accessing Application-Scoped Resources from Code

You can access application-scoped resources from code by using the Application.Resources property.  The property points to a ResourceDictionary that contains a collection of DictionaryEntry objects.

For resources defined in XAML, the key of each entry is a string and the value is an object of the associated resource type.

For example, for the SolidColorBrush resource shown below:

 <Application.Resources>
     <SolidColorBrush x:Key="greenBrush"  Color="Green"/>
 </Application.Resources>

The dictionary entry’s Key is the string “greenBrush” and the Value is a SolidColorBrush object with the Color property set to green.

 SolidColorBrush br = (SolidColorBrush)Application.Current.Resources["greenBrush"];
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

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: