How can I style the border and title bar of a window in WPF?
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)
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.
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:
- download the sample project here
- edit the generic.xaml file to customize the layout.
- enjoy :).
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.