如何将控件的样式与当前主题相匹配?(WPF)

ajl*_*ane 7 wpf themes styles

如果我使用WPF创建自定义控件,如何为与当前应用的主题(Aero,Luna,Classic等)匹配的控件提供样式?

例如,我想在使用Aero时应用以下内容:

<Style>
    <Setter Property="Background" Value="White"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

但是在使用Luna时应用不同的风格:

<Style>
    <Setter Property="Background" Value="#DFDFDF"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

我可以以某种方式扩展基本主题,以支持我的新控件吗?

Jas*_*zek 9

一些可能有用的链接:

http://arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows-theme.aspx

http://www.browsoft.com/tutorials/DefaultTheme.html

http://blogs.msdn.com/wpfsdk/archive/2007/07/31/using-themes-with-custom-controls.aspx

基本上,您为自定义控件创建资源字典,如下所示:

Classic.xaml (“Classic” Windows 9x/2000 look on Windows XP.)
Luna.NormalColor.xaml (Default blue theme on Windows XP.)
Luna.Homestead.xaml (Olive theme on Windows XP.)
Luna.Metallic.xaml (Silver theme on Windows XP.)
Royale.NormalColor.xaml (Default theme on the Windows XP Media Center Edition operating system.)
Aero.NormalColor.xaml (Default theme on the Windows Vista operating system.)
Run Code Online (Sandbox Code Playgroud)

将控件的不同样式放在这些文件中,它们将根据操作系统的当前主题加载.