tags:

views:

112

answers:

1

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?

+2  A: 

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>
  <Windows.Background>
    <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.WindowColorKey}}">
    </SolidColorBrush>
  </Windows.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

Lars Truijens
+1 - beat me by 10 seconds :)
IanR
huh my windows are white, I don't see anything in my xaml that sets the color.
Joel Barsotti
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
Joel Barsotti
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.
Lars Truijens