views:

263

answers:

2

How can I bind the default Window background color of the theme to a Window background?

I've tried the following:

<Window x:Class="Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Shell" 
    Height="300" 
    Width="300" 
    Background="{DynamicResource WindowBackgroundBrush}"
    >

But the background color renders as black and that does not seem right when using the Luna theme. Using the Luna theme I would expect the beige/brownish color often found in Windows XP.

UPDATE: After reading your answers, playing with StyleSnooper and thinking some more about this I've come to the following conclusion:

The Window will use SystemColors.WindowBrush as its background color by default. This color is white in most themes i've tried and that is probably OK. I believe white is also the Window background color in WinForms. However, the default Form background color in WinForms is not Window background but Control. So, if I want that color I have use SystemColors.ControlBrush as pointed out by Lucas.

At one point I was trying to achieve the brownish/beige Control color of WinForms on Windows XP. This is probably not possible on Windows Vista since Control color on Vista is kind of gray. Running a WinForms application on Windows Vista will not render it as beige/brownish, but gray. In this case I guess we have to apply our own custom styles to achieve the "original" Windows XP look on Vista.

Thanks everyone for helping me sort this out!

+1  A: 

I would have thought that simply leaving the Background property unset on your Window element would achieve this. The whole point of a theme is that it effects the default appearance of visual elements such as your Window.

EDIT You might look at StyleSnooper -- it will let you view the default template for a control (such as Window). You should be able to determine what property it is binding to for each theme.

Drew Noakes
Applying the Luna theme and leaving the Background property of my Window unset gives me a white background. I would expected a beige/brownish background as you would get in WinForms on Windows XP or a grayish background as you get in WinForms on Vista. If white background is the correct behavior maybe I need to rephrase my question.
Manga Lee
+1 for making me think differently about this and pointing me to StyleSnooper!
Manga Lee
+2  A: 

Does applying a theme actually override the system brushes as I would expect? If so, you should be able to do this:

<Window ...
    Background="{x:Static SystemColors.WindowBrush}
    ...>

Edit

As per Manga's comment, you'll probably want to use SystemColors.ControlBrush to achieve the desired effect, because WindowBrush on most systems is white. ControlBrush is the "off-white" colour you're seeing on Windows XP.

Matt Hamilton
i get white brackground from this, but following that suggestion, you could try `SystemColors.ControlBrush`, `SystemColors.ControlDarkBrush`, etc
Lucas
+1 for pointing me in the right direction. I would however like to accept an answer where the SystemColors.ControlBrush is applied to the Background like Lucas suggest. On your marks...
Manga Lee