Category Archives: WPF
In one of my projects, I needed a borderless window in WPF.
At first I thought this was a piece of cake, a matter of setting the border brush to null or transparent and maybe, just to be sure, put the border thickness to zero.
Well…Things turned out to be a bit more complicated than that.
It all depends on the scenario and the user’s need.
Borderless & Non-Resizable Window
Probably the easiest scenario is when you just need a borderless window even if it is non-resizable.
In that case, set WindowStyle property to None and set the ResizeMode property to NoResize.
Borderless & Resizable Window
If you need a borderless and resizable window at the same time, you should set WindowStyle property to None, set AllowsTransparency to True, ResizeMode to CanResizeWithGrip and Background to Transparent.
So far, all this looks pretty simple and easy, right? But in real life applications, you will have children elements inside your window.
If you have a native window as a child, let’s say a WebBrowser, hosted in the window with AllowsTransparency set to True, the child window will not appear at all. This is due to the fundamental “airspace” issue. In particular, composition involving different rendering technologies supports transparency only with entire top-level windows, not child windows.
I took the same code used below and added a WebBrowser to the window, The WebBrowser is visible in the non-resizable window only.
Luckily there is a workaround to that
Borderless & Resizable Window Hosting native windows
As mentioned in the workaround above, we need to create an ‘overlay’ window containing the child and set the borderless resizable window as its owner.
Note that the Overlay window has to be moved/resized in response to the owner window moving.
The class Win32 to do all the calculations:
It’s possible I missed a scenario or two , so I would love to hear about them!