.NET Zone is brought to you in partnership with:

Rabeb is a fresh graduate computer engineer. She specializes in User Experience Technologies including Windows Phone 7 and Windows 8, in addition to C# and .NET Technologies. She was selected for the Microsoft reality show Career Factor as Windows Phone 7 Finalist .She is passionate about new technologies . She is an avid proponent of social media , enjoy blogging http://rabeb.wordpress.com and tweeting @Rabeb_Othmani Rabeb is a DZone MVB and is not an employee of DZone and has posted 7 posts at DZone. You can read more from them at their website. View Full User Profile

All About Borderless Windows in WPF

08.08.2013
| 5453 views |
  • submit to reddit

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.

code1

BorderlessNonREsizable

Borderless & Resizable Window

If you need a borderless and resizable window at the same time, you should set WindowStyle property toNone, set AllowsTransparency to TrueResizeMode to CanResizeWithGrip and Background toTransparent.

code2

borderlessResizable

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.

code3

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.

code4 

code5

The class Win32 to do all the calculations:

code6

code7

BorderlessResizableWithChild

 It’s possible I missed a scenario or two , so I would love to hear about them!

Published at DZone with permission of Rabeb Othmani, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)