When I was writing the article about
saving WPF Application screens or controls as images, I started thinking "This would be a great time to write an article about extending the FrameworkElement class to enhance our User Interfaces." Under this premise, we can create a couple simple
Extension Methods that can really enhance some of our UIs. The upcoming series of articles will cover developing a library of extension methods we can use to enrich our user experiences with just a little code.
The series breakdown is as follows:
Creating and Consuming our Library - In this article we are going to set up our library project, discuss the structure of the final library, and create our class container. We are also going to discuss how we will use this library in our projects.
Show Default and Wait Cursors - These two extension methods will allow us to very quickly set Wait and Arrow cursors on any control. This allows us to do something like: Set the wait cursor, do some operation, show default cursor.
Animating Fades on User Interface Elements - In this article we will create an overloaded method that will allow us to fade a control to a specific opacity, as well as give us the ability to fade In or Out. A scenario for this might be to fade a window out, open a dialog, and after the dialog call, fade the window back in. This is a scenario we see on the Web all the time. You visit a page, click Login, the window disables and fades, a new window opens, we log in, the login window closes, and the parent window fades back in.
Save a Window or Control as an Image - Expanding on the previous article about how to save a window or control as an image, I decided to bake this functionality into the FrameworkElement class itself with a couple of cool overloads.
The complete source code is available for download here.