How to create a ResourceDictionary in Windows Phone 7?
July 27, 2011The Visual Studio templates do not offer the creation of a ResourceDictionary for Windows Phone 7 Silverlight applications by default. However, you can create and add one manually.
As a first step, just add an existing .xaml file to your project and make sure its BuildAction property is set to Resource.
The file should contain at least these lines of XAML code.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> </ResourceDictionary>
Then, define whatever resources your application needs inside this dictionary.
To use the defined resources, simply include the dictionary in your PhoneApplicationPage with these lines of code:
<phone:PhoneApplicationPage.Resources> <ResourceDictionary x:Key="dict"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="ResourceDictionary.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </phone:PhoneApplicationPage.Resources>