设置使用资源窗口背景色 [英] Setting Window background color using resource

查看:202
本文介绍了设置使用资源窗口背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用资源来设置主窗口的颜色在我的WPF应用程序。由于资源的声明而来的窗口申报(我导入资源字典),我不能使用背景后窗口的对象。所以,我想我会设置背景是这样的:

I need to use a resource to set the color of the main window in my WPF application. Since the resource declaration comes after the window declaration (I am importing a resource dictionary), I can't use a Background property in the Window object. So, I thought I would set the background this way:

<Window.Resources>
...
</Window.Resources>

<Window.Background>
    <SolidColorBrush Color="{StaticResource WindowBackgroundBrush}"  />
</Window.Background>

我的语法是有点过,因为对象将不承担其Color属性画笔资源。有什么解决?感谢您的帮助。

My syntax is a bit off, since the object won't take a brush resource for its Color property. What's the fix? Thanks for your help.

推荐答案

试试这个

<Window.Background>
    <StaticResource ResourceKey="WindowBackgroundBrush" />
</Window.Background>

这篇关于设置使用资源窗口背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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