ResourceDictionary in WP7

27 Sep

WP7 is based on Silverlight 3+ and by default it’s not possible to create a new resource dictionary. However it’s pretty easy to work around – just follow the same guidelines as if it was in Silverlight 3.

1) Create a new Class and rename it YourResourceDictionary.xaml (or whatever fits you).

2) Replace the content from the Class with the content you need:

<ResourceDictionary
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” >
<!– Your resources goes here –>
</ResourceDictionary>

3) Unless you’re creating a Generic.xaml resource dictionary in the Themes folder you need to add the resource dictionary to the list of merged resource dictionaries in your App.xaml file:

<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source=”YourResourceDictionary.xaml” />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

Your resource dictionary will now be loaded as part of the application resources to your WP7 application.

by xamlgeek
twitter.com/thomasmartinsen

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 )

w

Connecting to %s

%d bloggers like this: