Silverlight企业级开发中,项目中会出现大量的Style资源文件,如何将这些XAML文件打包成dll,以满足动态改变Theme的需求呢?通过参考Toolkit的源码中有关Theme.dll
的实现方式,本文将详细叙述这一过程:
1.创建一个Silverlight Class Library,命名为BlackColorTheme.
2.创建需要的ResourceDictionary
这里创建了ButtonStyle.xaml,HyperlinkButton.xaml2个文件,Build Action设置为Resource
以ButtonStyle为例,我们设置点简单的样式:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button" x:Key="DefaultButtonStyle">
<Setter Property="Background" Value="Black"></Setter>
</Style>
<Style TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}"/>
</ResourceDictionary>