如何将窗口背景绑定到主题的窗口背景颜色?

发布于 2024-08-07 04:21:56 字数 1115 浏览 6 评论 0原文

如何将主题的默认窗口背景颜色绑定到窗口背景?

我尝试了以下方法:

<Window x:Class="Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Shell" 
    Height="300" 
    Width="300" 
    Background="{DynamicResource WindowBackgroundBrush}"
    >

但是背景颜色呈现为黑色,并且在使用 Luna 主题时似乎不正确。使用 Luna 主题时,我期望 Windows XP 中常见的米色/棕色颜色。

更新:阅读您的答案后,玩 StyleSnooper 并对此进行了更多思考,我得出以下结论:

默认情况下,窗口将使用 SystemColors.WindowBrush 作为其背景颜色。在我尝试过的大多数主题中,这种颜色都是白色,这可能没问题。我相信白色也是 WinForms 中的窗口背景颜色。然而,WinForms中默认的Form背景色不是Window背景而是Control。因此,如果我想要那种颜色,我可以使用 Lucas 指出的 SystemColors.ControlBrush

有一次,我试图在 Windows XP 上实现 WinForms 的棕色/米色控制颜色。这在 Windows Vista 上可能是不可能的,因为 Vista 上的控制颜色是灰色的。在 Windows Vista 上运行 WinForms 应用程序不会将其呈现为米色/棕色,而是呈现为灰色。在这种情况下,我想我们必须应用我们自己的自定义样式才能在 Vista 上实现“原始”Windows XP 外观。

感谢大家帮我解决这个问题!

How can I bind the default Window background color of the theme to a Window background?

I've tried the following:

<Window x:Class="Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Shell" 
    Height="300" 
    Width="300" 
    Background="{DynamicResource WindowBackgroundBrush}"
    >

But the background color renders as black and that does not seem right when using the Luna theme. Using the Luna theme I would expect the beige/brownish color often found in Windows XP.

UPDATE: After reading your answers, playing with StyleSnooper and thinking some more about this I've come to the following conclusion:

The Window will use SystemColors.WindowBrush as its background color by default. This color is white in most themes i've tried and that is probably OK. I believe white is also the Window background color in WinForms. However, the default Form background color in WinForms is not Window background but Control. So, if I want that color I have use SystemColors.ControlBrush as pointed out by Lucas.

At one point I was trying to achieve the brownish/beige Control color of WinForms on Windows XP. This is probably not possible on Windows Vista since Control color on Vista is kind of gray. Running a WinForms application on Windows Vista will not render it as beige/brownish, but gray. In this case I guess we have to apply our own custom styles to achieve the "original" Windows XP look on Vista.

Thanks everyone for helping me sort this out!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叹梦 2024-08-14 04:21:56

应用主题实际上会像我期望的那样覆盖系统画笔吗?如果是这样,您应该能够执行以下操作:

<Window ...
    Background="{x:Static SystemColors.WindowBrush}
    ...>

编辑

根据 Manga 的评论,您可能需要使用 SystemColors.ControlBrush 来实现所需的效果,因为大多数系统上的 WindowBrush 是白色的。 ControlBrush 是您在 Windows XP 上看到的“灰白色”颜色。

Does applying a theme actually override the system brushes as I would expect? If so, you should be able to do this:

<Window ...
    Background="{x:Static SystemColors.WindowBrush}
    ...>

Edit

As per Manga's comment, you'll probably want to use SystemColors.ControlBrush to achieve the desired effect, because WindowBrush on most systems is white. ControlBrush is the "off-white" colour you're seeing on Windows XP.

白昼 2024-08-14 04:21:56

我本以为只需在 Window 元素上保留 Background 属性未设置即可实现此目的。主题的全部要点在于它会影响视觉元素(例如Window)的默认外观。

编辑您可以查看StyleSnooper ——它可以让您查看控件(例如 Window)的默认模板。您应该能够确定它为每个主题绑定到什么属性。

I would have thought that simply leaving the Background property unset on your Window element would achieve this. The whole point of a theme is that it effects the default appearance of visual elements such as your Window.

EDIT You might look at StyleSnooper -- it will let you view the default template for a control (such as Window). You should be able to determine what property it is binding to for each theme.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文