8
votes

Is there any way to make a WPF window transparent without losing the non-client area (borders, title bar, close/minimise/maximise buttons)?

Setting 'AllowsTransparency' to 'true' requires that 'WindowStyle' be set to 'None' (as explained in this answer), which removes the non-client area.

One of the WPF developers blogged about how transparent windows work in WPF, and why it would have been difficult to implement support for non-client area transparency.

No matter what your window styles may suggest, transparent WPF windows do not have any visible non-client area. This is fine for many scenarios where the intent is to create a custom window shape, but it can be annoying for people who just want to "fade in" a normal window.

A WPF-only solution, then, seems out of the question.

Calling the native SetLayeredWindowAttributes function and passing a WPF window's handle and LWA_ALPHA has no effect, as expected.

The only other approach I can think of is hosting WPF content within a Win32 (or possibly WinForms) window. I suspect trying to do this will result in airspace issues, however.

WPF layered windows have different capabilities on different operating systems ... WPF does not support transparency color keys, because WPF cannot guarantee to render the exact color you requested, particularly when rendering is hardware-accelerated.

I'm not sure if I'm reading the above correctly, but it sounds like trying to host WPF content featuring transparency is not possible.

Any ideas?

Transparent Notepad2 Window

3

3 Answers

2
votes

You can customize non-client area using library from ms called WPF Chrome. Check this article: 'Custom Window Chrome'.

With this library you can make chrome transparent and change many more things.

2
votes

Fluidkit has an implmentation of a glass window, which I think is what you're after.

0
votes

The only way to achieve this is by using setWindowCompositionAttribute() method and setting it to invalid state.

Just take a look at this code: https://github.com/riverar/sample-win32-acrylicblur

Instead of setting composition attribute to

ACCENT_ENABLE_ACRYLICBLURBEHIND

set it to

ACCENT_INVALID_STATE

It will make the client area completely transparent.

Note: the SetWindowCompositionAttribute() is a part of undocumented API. It can be changed any time.