I have multiple silverlight project that I would like to use the same styles, colour scheme, and some templated objects.
开发者_开发知识库How do I accomplish this?
One way to do this would be to create a new silverlight class library which would be your shared theme/style assembly which would be referenced by the other silverlight projects. This assembly would have one or more Resource Dictionary XAML files in it which could define all of your styles, brushes and templates. You could even set up some cascading style hierarchies using the BasedOn attribute of the Style class.
You could then use MergedDictionaries to merge these styles into your application either at the App.xaml-level or on a page-level basis.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/SharedThemeAssembly;component/MyStyles.xaml"/>
...other ResourceDictionaries to merge in...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
You would then reference the shared styles / brushes as you normally would any other StaticResource.
There are two options, first as Dan indicates you could create a library that is shared by the other projects. If the clients access several of your projects and your projects use application library caching then you reduce the total download size.
The other approach is to create a Resource dictionary in one project, then add the same file to the other projects. Note in the Add Existing Item dialog the add button has a small drop down image, drop it down and then select "Add as Link".
This leaves the dicitionary as a simple Xaml file. One advantage I can see for this is to actually leave the dictionary file out of the Xap and just place it in the clientBin folder (or whatever the folder that the Xap is placed in). This approach allows all the Xaps to share the single dictionary (in the same way the first approach does) but allows the Xaml to be tweaked without messy rebuilds.
精彩评论