16

Okay here is a softball beginner WPF question.

By default the background of the window is white. I'm trying to hack in an error reporting form and I want to emulate the more standard windows look and feel.

Any easy way to grab the default color for the background?

0

1 Answer 1

34

Using the SystemColors class and specifically the WindowColor property. When using xaml it is better to use DynamicResources and therefore use the ...Key properties. That way your application changes in the fly when the user changes the color in Windows.

<Window>
  <Window.Background>
    <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.WindowColorKey}}">
    </SolidColorBrush>
  </Window.Background>
</Window>

Using the ...BrushKey properties makes it easier to use when in need of a brush

<Window Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
</Window>

PS: WPF Windows should already have the correct color by default

5
  • 1
    huh my windows are white, I don't see anything in my xaml that sets the color. Commented Dec 29, 2009 at 18:52
  • 3
    Got it, it's the fact that the background on a winform app is defaulted to the control color. Anyway I got it, thank you so much. :D Commented Dec 29, 2009 at 18:55
  • Yes, that is what I said in my PS. But you asked for it. :) White is the correct color of a Window background in your theme. Can't get more standard then standard. Commented Dec 29, 2009 at 18:57
  • Using this still makes my WPF window white. Commented Sep 21, 2017 at 18:48
  • 1
    Yes, that because it should be. Gray is not the correct color. Commented Sep 21, 2017 at 19:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.