protected override void OnStartup(StartupEventArgs e)
{
var uri = new Uri("/PresentationFramework.AeroLite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/AeroLite.NormalColor.xaml", UriKind.Relative);
App.Current.Resources.Source = uri;
base.OnStartup(e);
}
效果如下,看着还有一点小清新的感觉。
我们还可以以同样的方式实现复古的Win XP效果:
或者更复古的Win 98效果:
基于同样的原理,我们也可以只设置某个控件样式:
代码如下:
private void button_Click(object sender, RoutedEventArgs e)
{
var uri = new Uri("/PresentationFramework.AeroLite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/AeroLite.NormalColor.xaml", UriKind.Relative);
var resourceDictionary = Application.LoadComponent(uri) as ResourceDictionary;
(sender as FrameworkElement).Resources.MergedDictionaries.Add(resourceDictionary);
}
最后需要介绍的一个知识点是:如果我们有自定义控件的时候,如何像系统控件那样根据不同的系统呈现不同的样式呢?方法是:在Theme文件夹下加上对应的样式资源即可。
具体可以参看这篇文章:Add Windows 8 Aero Theme Support to your WPF Custom Control