Search code examples
c#wpfxamlivalueconverterbrush

How to get the default BackGround brush of a WPF button


I have a converter that converts an enumeration to a WPF brush. So basically I return brushes depending on the provided enum value.

The only problem I have is to get the default brush that the system uses.

I'd like to do something like:

default:
    return new SolidColorBrush(Button.DefaultBackground);

Is there a way to solve this?


Solution

  • You can find the default colors and brushes from System.Windows.SystemColors.

    SystemColors.WindowBrush is quite likely the one you're looking for. It's the "The background color in the client area of a window."

    Here's sample code on how to use the brush from code behind:

        private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
        {
            this.MyButton.Background = SystemColors.HighlightBrush;
        }
    

    So no special tricks needed to access them.