3

I want to change the background color of button to system color. Just like I am changing the button color

button2.Background = Brushes.Blue; 

to blue. But no I want to Change the color to system color.

1
  • There are a lot of different system colors. Which one do you want? Commented Feb 25, 2015 at 15:57

4 Answers 4

2

You can get system color from System.Windows.SystemColors

button2.Background = System.Windows.SystemColors.MenuHighlightBrush;

WPF Background is of type System.Windows.Media.Brush. You can set another color like this:

// using System.Windows.Media;

button2.Background = Brushes.White;

button2.Background = new SolidColorBrush(Color.White);

button2.Background = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0);
Sign up to request clarification or add additional context in comments.

Comments

1

I Hope this helps

<Button 
      Background="{DynamicResource {x:Static SystemColors.DesktopBrushKey}}" 
      Content="Hello, World!" />

Comments

0

Background is of type Brush. But you can create a solid brush out of the system color and use that.

SolidBrush systemColorBrush = new SolidBrush(systemColor); // Create SolidBrush from color
button2.Background = systemColorBrush;

1 Comment

solidbrush gives me error in WPF, But it works perfectly in Windows Form.
0

You can try something like:

button2.Background = SystemColors.ActiveCaptionBrush;

SystemColors belong to the System.Windows namespace.

1 Comment

It is not giving the actual system color. I want it to pick from theme

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.