How to make window corners round in XAML?  
Author Message
Kevin Lew





PostPosted: Windows Presentation Foundation (WPF), How to make window corners round in XAML? Top

Hi all,

I have been trying, to no avail, to make the corners of my application's window round. There are no RadiusX and RadiusY properties.

I even tried a border and specified its CornerRadius but then the border appears inside the outer window and the rectangular corners and edges of the primary window are still there.

Does anybody know how to achieve that

Thank you in anticipation!

Kevin



Visual Studio 200847  
 
 
IanG





PostPosted: Windows Presentation Foundation (WPF), How to make window corners round in XAML? Top

The thing to understand about window borders is that they are special, in the sense that they work a bit differently from the rest of WPF. The reason for this is that the window border is at the edge where the classic Win32 world meets the new WPF world.

In XP at least, the default window border is essentially a Win32 thing. (The story is a little more complex in Vista if you have glass. But the fact remains that the window border is handled differently from the contents of the window.)

The first question I need to ask is this: are you turning the default window 'chrome' off (I.e. are you disabling the usual title bar, resize borders, and so on.) If you're not, then there's only a limited amount you can do to control the shape of these, and it's probably a bad idea to try to do so.

But for now, I'll assume that you've turned these off, and that the reason you want to change the window shape is because you're creating your own custom look for the window.

The technique for controlling the shape of your windows is to exploit transparency. Basically, you render the contents in whatever shape you like, leaving the rest transparent, and voila: shaped window.

Nathan Dunlap shows an example of how to do this:

http://www.designerslove.net/2006/03/non-rectangular-windows.html

This is actually much more powerful than the approach you're looking for would be. A border radius would just let you round off the edges. But the technique Nathan shows here lets you create windows of any shape you like. (And they will have nice anti-aliased edges. And you can even use transparency.)


 
 
lester - MSFT





PostPosted: Windows Presentation Foundation (WPF), How to make window corners round in XAML? Top

you might also want to read:

http://blogs.msdn.com/llobo/archive/2006/03/09/543762.aspx


 
 
Kevin Lew





PostPosted: Windows Presentation Foundation (WPF), How to make window corners round in XAML? Top

Yup, got it. Thank you both Ian and Lester! I think I can combine the ideas and come up with something that will meet my requirements.

Thanx again,

Kevin


 
 
Ashish Shetty - MSFT





PostPosted: Windows Presentation Foundation (WPF), How to make window corners round in XAML? Top

June CTP introduces native support for transparent Windows in WPF. You need to specify AllowsTransparency="True" WindowStyle="None" Background="Transparent". Lauren has a post on how you can use this to get the rounded corners you wanted.


 
 
Kevin Lew





PostPosted: Windows Presentation Foundation (WPF), How to make window corners round in XAML? Top

Thank you! It looks like this is getting better and better...