简体   繁体   中英

Change control's Background based on the Windows theme color wpf

In my application I have a control whose background is set based on the user input, by the following code:

m_ToolBar.Background = (m_IToolbar.UseBackColor) ?
new SolidColorBrush(m_IToolbar.BackColor): m_DefaultWindowsBrush;

where m_IToolbar.UseBackColor is a boolean whether to update the color or not, if not then restore back to the default windows color which i have hardcoded in the initialise method.

Is there a way to get the default windows color other than hardcording( which has further problem if I change the windows theme color).

You can use the SystemColors Class . Specifically the SystemColors.ControlBrush Property

From above link:

WPF exposes a swatch of colors that comprise the current Windows system theme. These are available in the SystemColors class as Colors, Brushes, and corresponding ResourceKeys (for binding with dynamic notification of changes to these colors, eg if the user switches Windows themes).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM