如何将控件的样式与当前主题相匹配?(WPF) [英] How do I match my controls' styles to the current theme? (WPF)

查看:35
本文介绍了如何将控件的样式与当前主题相匹配?(WPF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I create a custom control with WPF, how can I provide styles for the control that match the currently applied theme (Aero, Luna, Classic, etc.)?

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

For example I'd like to apply the following when using Aero:

<Style>
    <Setter Property="Background" Value="White"/>
</Style>

但是在使用 Luna 时应用不同的样式:

But then apply a different style when using Luna:

<Style>
    <Setter Property="Background" Value="#DFDFDF"/>
</Style>

我能否以某种方式扩展基本主题以支持我的新控件?

Can I somehow extend the base themes to provide support for my new control?

推荐答案

一些可能有用的链接:

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

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

Basically you create resource dictionaries for your custom controls named like this:

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.)

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

Put the different styles for your controls in those files and they will be loaded based on the current theme of the OS.

这篇关于如何将控件的样式与当前主题相匹配?(WPF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆