Windows 7 中的 WPF 按钮背景
我之前有 Windows XP,设置 wpf 按钮背景总是有效,但从 Windows 7 开始,背景始终设置为蓝色。我该如何解决这个问题?
I had windows xp before and setting the wpf button background always worked but since windows 7 the background is always set to blue. How could i fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要为按钮制作自己的模板。 (我想这只是您正在努力解决的悬停颜色,而不是遵循背景属性的基本颜色)。
这是一个非常简单的按钮模板,可能会帮助您入门。
BackBrush 和 ForeBrush 需要进行设置以适应。 (它们是应用程序其余部分的后部和前部,因此在本示例中它们向后看)
You'll probably need to make your own template for the buttons. (I guess it's just the hover colour which you're struggling with, not the basic colour, which does follow the Background property).
Here's a very simple button template, which might help you get started.
BackBrush and ForeBrush will need setting to suit. (And they're the Back and Fore of the rest of the application, so they look backwards in this example)
要使用背景,请将此样式添加到 Window.Resources(或任何其他应用程序资源字典):
如果您不需要重新定义按钮模板(按钮的几何外观),则此样式有效。这里我们没有指定
Style x:Key
那么该样式将应用于指定资源范围内的所有按钮。要指定具有不同外观的样式,您应该为每个样式标记x:Key="StyleName"
,然后在按钮中定义样式Style="{DynamicResource StyleName}"
或Style="{DynamicResource StyleName}"
For playing with Backgrounds add to Window.Resources (or any other App ResourceDictionary) this style:
This works if you don't need to redefine Button template (geometrical appearance of button). Here we aren't specifying
Style x:Key
then this style will be applyed to all button in specified resource scope. To specify styles with different appearances you should each style mark withx:Key="StyleName"
and then in button define styleStyle="{DynamicResource StyleName}"
orStyle="{DynamicResource StyleName}"