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

138,377

Solution 1

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)

Solution 2

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.

Solution 3

I found a more straight forward solution from @DK comment in this question, the solution is written by Alex and described here with source, To make customized window:

  1. download the sample project here
  2. edit the generic.xaml file to customize the layout.
  3. enjoy :).

Solution 4

Such statements as “you can't because only Windows can control the non-client area” are not quite true — Windows lets you specify the dimensions of the non–client area.

The downside is this is possible only through the Windows' kernel methods, and you're in .NET, not C/C++. Anyway, there is P/Invoke at our disposal. Indeed, the whole of the Windows Form UI and console application I/O methods are offered as wrappers that make system calls under the hood. Hence, as documented in MSDN, it is completely possible to use P/Invoke to access those methods that are needed to set up the non–client area.

However, this is a harder–than–currently–necessary solution I came up with a lot of time ago. Luckily, as of .NET 4.5, you can use the WindowChrome class to adjust the non-client area like you want. Get started here and here, a guide to change the window border dimensions however you want. By setting it to 0, you'll be able to implement your custom window border in place of the system's one.

Solution 5

I suggest you to start from an existing solution and customize it to fit your needs, that's better than starting from scratch!

I was looking for the same thing and I fall on this open source solution, I hope it will help.

Share:
138,377
Marcel Gosselin
Author by

Marcel Gosselin

Software developer from Montréal currently working for Ubisoft.

Updated on September 09, 2021

Comments

  • Marcel Gosselin
    Marcel Gosselin over 2 years

    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.