Kris
Kris

Reputation: 640

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).

Upvotes: 2

Views: 3861

Answers (1)

Mark Hall
Mark Hall

Reputation: 54532

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, e.g. if the user switches Windows themes).

Upvotes: 3

Related Questions