在Silverlight Tookit 中提供了大约十种主题,大家可以根据自己的喜好,很容易就在项目中实现
动态换肤效果。当然其官方还推荐了几个制作主题的插件,使用这些 Blend插件可以很方便的生成各种
风格颜色的主题。
好了,下面开始今天的正文。
首先我们要下载该Tookit并将其中的相应DLL文件:Microsoft.Windows.Controls.Theming.dll加
载到当前的示例中,另外就是相关的theme文件了,我已将10种主题文件放在了这个DEMO的themes
文件夹下:
并以“内容”方式作为"生成操作"的选项,如下:
我们可以直接在XAML文件中声明使用主题的元素,比如:
<UserControl
..
xmlns:theming="clr-namespace:Microsoft.Windows.Controls.Theming;assembly=Microsoft.Windows.Controls.Theming"

>
<!--ShinyDarkPurple-->
<StackPanel Width="100"
theming:ImplicitStyleManager.ApplyMode="Auto"
theming:ImplicitStyleManager.ResourceDictionaryUri="themes/ExpressionLight.xaml">
<Button Content="Button"/>
<CheckBox Content="CheckBox"/>
<RadioButton Content="RadioButton"/>
<Slider/>
<ListBox/>
<ProgressBar Height="15" Value="30"/>
<controls:Expander ExpandDirection="Down"/>
</StackPanel>
<!--ShinyDarkGreen-->
</UserControl>
这样在该StackPanel下的所有控件样式均应用了ExpressionLight主题。另外我们也可以在CS
文件中对指定的控件设置相应的主题,比如本DEMO中所写的代码:
public Page()
{
InitializeComponent();
this.ThemeList.SelectionChanged += new SelectionChangedEventHandler(ThemeList_SelectionChanged);
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
ThemeList.Items.Add(new ComboBoxItem() { Name = "ExpressionDark", Content = "ExpressionDark", DataContext = "themes/ExpressionDark.xaml", IsEnabled = true });
ThemeList.Items.Add(new ComboBoxItem() { Name = "ExpressionLight", Content = "ExpressionLight", DataContext = "themes/ExpressionLight.xaml