Use an External ResourceDictionary in a WindowsPhone 7 app
windows-phone-7
Solution
I've managed to get this to work using the following steps:
- Created a standard WP7 application using the "Windows Phone Application" application template called "WP7ExternalResourcesTest".
- Added a project to the same solution using the "Windows Phone Class Library" template called "WP7ExternalResourcesTestLibrary".
- Removed the default Class.cs file form the library project.
- Added a file called "External.xaml" using the "XML file" template and set the "Build Action" to "Page".
Added the following XAML to the new XAML file:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="ForegroundBrush" Color="Red" />
</ResourceDictionary>
- Built the library project, and then added a reference to it from the WP7ExternalResourcesTest project.
In WP7ExternalResourcesTest, opened App.xaml and changed the `Application.Resources` section to the following:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WP7ExternalResourcesTestLibrary;component/External.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
- In MainPage.xaml, added `Foreground="{StaticResource ForegroundBrush}"` to the `TextBlock` named "PageTitle".
- Ran the application in the emulator. The end result was that the `TextBlock` correctly displayed the words "page name" in red.
Hope this helps.
Problem
I am trying to create an ResourceFile Called DataTemplate.xaml in an external dll and use that in a WP7 page. When I do the following in the header of my Page I get an error ` <ResourceDictionary Source="pack://application:,,,/WP7SharedClassLibrary;component/DataTemplate.xaml" /> ` The error is "Current project does not support 'application' as the authority component of the pack URI." Has anyone else come across this and solved this?