Wednesday 18 April 2012

The Resource ‘X’ Could not be resolved : WP7

A while back, I took one of my WP7 programs, and saved it as a Template, so it was easy to create a new WP7 app with all my framework code already built into the app.

What I didn’t notice at the time though, was that my Merged resource dictionary was not being used to render in the VS2010 xaml designer, though they were working correctly in the actual program, and in Blend.

After spending a few hours searching on the web, and trying “voodoo” solutions, I found the answer (or thought I did, until I began writing this up, which wasted another hour or two)

My original solution was built with this ResourceDictionary located in my Framework folder:

<!--Application Resources-->
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/AppDetails.xaml" />
<ResourceDictionary Source="/Framework/Resources/FrameworkResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>


Both xaml files above were included in the build as Content


This is the code I needed instead:


<!--Application Resources-->
pplication.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyApp;component/Framework/Resources/FrameworkResources.xaml" />
<ResourceDictionary Source="/MyApp;component/Resources/AppDetails.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>


And to get this to work, the xaml files needed to be changed to Page


You must also make sure your App.xaml file is marked with a build action of ApplicationDefinition and your App.xaml appears to have to be in the root of your project.


I had some cases where it appeared to work with various combinitions of all of the above, but after a restart of visual studio, occasionally it would again lose the resources in the designer, so the only apparent way to make this work is to follow the exact steps above.

No comments:

Post a Comment