views:

1024

answers:

2

I have a silverlight class library (not a top-level application) with several user controls that are shared by different silverlight applications. I have gone through and pulled out several styles and brushes for the controls and put them in a separate XAML file as a resource dictionary which I bring into each control as a merged resource dictionary. Right now this works great in my top-level applications, as long as I keep that resource dictionary as a "Resource" build action and reference it in that way from the controls.

What I would really like to do is have this resource dictionary XAML file as a "Content" build action which gets copied into the top-level XAP, so that the XAML can be swapped out in the XAP file without needing to rebuild the project. Whenever I try to set this up, the XAML file will get copied into the output bin for the class library project, but it will never get copied to my top-level silverlight application project output directory or into the final XAP file.

What is the best way to accomplish this? The XAML resource dictionary is essentially a dependency of the class library, and the class library (of user controls) is a dependency of the top-level silverlight application.

A: 

Will merged dictionaries meet your needs?

Best,
Mark

Mark Cooper
Merged Resource Dictionaries are what I am using so save the styles and brushes in a separate XAML file, the problem is that the dictionary is part of my shared Silverlight Class Library, not a Silverlight Application. When I set the build action to Content and Copy Always it is never getting copied into my applications XAP file. Just trying to find the best way to package and reference a resource from a dependent class library in the final XAP.
Dan Auclair
take a look at the cross project merged resource files at http://thoughtjelly.blogspot.com/2009/10/cross-project-mergeddictionaries-in.html
Mark Cooper
The OP specified the aim was to be able to swap the shared resource XAML file out of the XAP file without rebuilding. The shared resource assembly strategy referenced in Mark's post doesn't seem like it would accomplish this. To swap this XAML without rebuilding would require it be a content file in the XAP (not compiled into an assembly). The only way I know of to accomplish that is with a "Content" build item in the Silverlight Application project being built - thus the linked project file item is the way to go here.
Tim Erickson
+1  A: 

Add the ControlResources.xaml (the ResourceDictionary you want in your XAP) to the top-level XAP project as a link via Project->Add Existing Item->Add as Link (a drop down item on the Add button in the dialog), and set it to build as Content, also.

Tim Erickson
This seems like the best possible approach, just kind of annoying to have both a reference to a silverlight class library and a link to one of its output files in the silverlight app. Guess thats the only way its getting in the XAP without some post-build XAP repackaging hackery.
Dan Auclair
After testing some more things out, this approach works fine at runtime but doesn't appear to be "Blendable". When opening the top-level silverlight app in Expression Blend I get a whole bunch of errors... it seems that Blend can't follow the links in the project to the ResourceDictionary for the controls class library. Any ideas on how to get Blend to play well? This solution won't cut it if I can never properly open the project up in Blend.
Dan Auclair