Packaging ResourceDictionary for Silverlight Class Library
-
20-09-2019 - |
Question
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.
Solution
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.
OTHER TIPS
Will merged dictionaries meet your needs?
- http://www.silverlight.net/learn/videos/silverlight-videos/hdi-sl3-merged-resources/
- http://thoughtjelly.blogspot.com/2009/10/cross-project-mergeddictionaries-in.html
- http://www.liquidjelly.co.uk/supersearch/?q=silverlight%20merged%20resource%20dictionaries&lang=en-GB
Best,
Mark