Packaging ResourceDictionary for Silverlight Class Library
Asked Answered
G

2

6

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.

Glycerol answered 18/12, 2009 at 0:56 Comment(0)
U
1

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.

Unintentional answered 18/12, 2009 at 23:27 Comment(2)
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.Glycerol
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.Glycerol
B
0

Will merged dictionaries meet your needs?

Best,
Mark

Barreto answered 18/12, 2009 at 16:19 Comment(3)
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.Glycerol
take a look at the cross project merged resource files at thoughtjelly.blogspot.com/2009/10/…Barreto
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.Unintentional

© 2022 - 2024 — McMap. All rights reserved.