Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I style the border and title bar of a window in WPF?

Tags:

styling

wpf

xaml

We are developing a WPF application which uses Telerik's suite of controls and everything works and looks fine. Unfortunately, we recently needed to replace the base class of all our dialogs, changing RadWindow by the standard WPF window (reason is irrelevant to this discussion). In doing so, we ended up having an application which still looked pretty on all developer's computers (Windows 7 with Aero enabled) but was ugly when used in our client's environment (Terminal Services under Windows Server 2008 R2).

Telerik's RadWindow is a standard user control that mimicks a dialog's behaviour so styling it was not an issue. With WPF's Window though, I have a hard time changing its "border". What I mean by "border" here is both the title bar with the icon and the 3 standard buttons (Minimize, Maximize/Restore, Close) and the resize grip around the window.

How can I change the looks of these items:

  • Title bar color
  • 3 standard buttons
  • Window's real border color

With round corners if possible.

like image 674
Marcel Gosselin Avatar asked Apr 02 '12 14:04

Marcel Gosselin


People also ask

How do I change the color of the title bar in WPF?

You can change the background colour of the TilteBar by overriding the RibbonWindow template in App. Xaml and change the value of Background property in TitleBarStyleKey. The following code example demonstrates the same.

What is WindowChrome in WPF?

The WindowChrome class lets you put WPF content in the window frame by extending the client area to cover the non-client area. At the same time, it retains system behaviors through two invisible areas; the resize border and caption areas.

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.


2 Answers

Those are "non-client" areas and are controlled by Windows. Here is the MSDN docs on the subject (the pertinent info is at the top).

Basically, you set your Window's WindowStyle="None", then build your own window interface. (similar question on SO)

like image 72
Muad'Dib Avatar answered Nov 09 '22 15:11

Muad'Dib


You need to set

WindowStyle="None", AllowsTransparency="True" and optionally ResizeMode="NoResize"
and then set the Style property of the window to your custom window style, where you design the appearance of the window (title bar, buttons, border) to anything you want and display the window contents in a ContentPresenter.

This seems to be a good article on how you can achieve this, but there are many other articles on the internet.

like image 20
Lescai Ionel Avatar answered Nov 09 '22 16:11

Lescai Ionel