如何以编程方式将WPF控件的颜色设置为系统颜色,以便它在配色方案更改时更新? [英] How can I set a WPF control's color to a system color programmatically, so that it updates on color scheme changes?
本文介绍了如何以编程方式将WPF控件的颜色设置为系统颜色,以便它在配色方案更改时更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在WPF的代码隐藏中做到这一点?
How can I do this in WPF's code-behind?
<Grid Background="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}"/>
推荐答案
我刚刚找到了一个丑陋的解决方案:
I just found an ugly solution:
grid1.SetResourceReference(
Control.BackgroundProperty,
SystemColors.DesktopBrushKey);
我希望有人能发布更好的代码(我想看一下grid1.Background = BackgroundBrush之类的东西,因为SetResourceReference的语法比Windows Forms倒退了一步.)
I hope someone will post a better one (I'd like to see something like grid1.Background = BackgroundBrush, because the syntax of SetResourceReference is a step backwards from Windows Forms).
这篇关于如何以编程方式将WPF控件的颜色设置为系统颜色,以便它在配色方案更改时更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文