Silverlight: Multiple project sharing the same style files

♀尐吖头ヾ 提交于 2020-01-12 19:47:36

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2268658/silverlight-multiple-project-sharing-the-same-style-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!