Wednesday, July 04, 2007

WPF - Non-Rectangular Window Sweetness

Recently, I have been working on a small WPF project. It is truly an exciting project and I hope to provide more details on the specifics later. Regardless, I learned something really cool about WPF while working on this project that I felt I needed to share.

My WPF application is not an archetypal rectangular window. It has a very well designed looking interface that really makes the application look nice. One of the distinguishing features is a large image in one of the corners of Window. As an illustration, imagine the application window looking like a more complicated version of the following:



I wanted to ensure that users could only drag the window if they were clicking within the bounds of the window. This means I needed to take into account the area occupied by the green ellipse. I learned how to create non-rectangular windows through this article.

I knew I could use the Path element to define the bounds of my window. However, the following discovery pleasantly surprised me. I was able to use a graphic, which was already created by a graphic designer, and simply make the background of the image file transparent. WPF automatically created the bounds of the window tightly bound AROUND the image.

This made my life significantly simpler. I was afraid I was going to be tinkering with Paths all day long. Very sweet.

My book "Silverlight 1.1. in Action" is coming along nicely. There should be some content available for consumption soon. Thanks for reading!

No comments: