Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF, can you get the default windows colors?

Tags:

.net

colors

wpf

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?

like image 651
Joel Barsotti Avatar asked Dec 29 '09 18:12

Joel Barsotti


People also ask

How do I change the background color in WPF?

Click the C1ColorPicker control once to select it. Navigate to the Properties window, and click the Background drop-down arrow, and choose Red or another color in the color picker.

How do I display a WPF window?

When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.

What is Window XAML?

XAML Islands is a technology that enables Windows developers to use new pieces of UI from the Universal Windows Platform (UWP) on their existing Win32 Applications, including Windows Forms and WPF technologies.


1 Answers

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

like image 87
Lars Truijens Avatar answered Oct 05 '22 11:10

Lars Truijens