Blog Archives

All about borderless windows in 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.

code1

BorderlessNonREsizable

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.

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!

Quick Tip: a work around the RadListBox’s SelectedIndex issue with Telerik Q1 2013

If you are working with Telerik RadListBox for Silverlight or WPF and if you upgraded your Telerik version to the Q1 2013 , you probably noticed that there is something wrong with it.

Basically the problem is when SelectedIndex is changed , the SelectedItem property is not updated and vice versa.

A classic scenario is when you try to set a by default selection:

_myListBox.SelectedIndex = 0;

If(_myListBox.SelectedItem != null)

   {

       //Do something

   }

This is not working anymore with Telerik Q1 2013 because SElectedItem is not updated.

What you can do is instead of  _myListBox.SelectedIndex = 0;

put  _myListBox.SetValue(RadListBox.SelectedItemProperty, _myListBox.Items[0]);

 

Wala Sourire