WPF in the eyes of a beginner

scru 0 Tallied Votes 168 Views Share

As a programmer who until very quite recently chose C#.NET as his main language, WPF was thrust upon me like an anvil in your favorite 90s cartoon. There was no avoiding it...

And for that, I'm glad -- mostly.

The Windows Presentation Foundation is a UI subsystem of the Microsoft .NET 3.0, (and 3.5 as of two days before this post). Using it, an application's user interface may designed completely in a special markup language called XAML.

For me, XAML was certainly comparable to HTML (a bonus since I have some experience with HTML and CSS, being an interim web developer at my workplace). Like HTML, XAML can be used to describe your windows' (web pages with HTML) content. You may also specify styles and templates for your controls, and apply them to a group of controls, or all if you so please; very much like cascading styles. XAML also supports gradients, bitmap effects, and shapes that can be applied to almost any control, so I could make all the buttons in my WPF app look like that anvil we talked about with very little effort, and they would still all work the same way.

Another cool thing about WPF is the sheer ease of doing animations. While I have only tried basic animations so far (moving controls around, shrinking and growing them, hiding and showing them with a fade effect), I can tell you that the manner in which they were done was rather easy to grasp. The XAML mark-up for animations, while extensive, is rather intuitive. Of course, for those who want to skip the mark-up altogether, you may be delighted to learn that all of those animations mentioned above were done with one or two lines of code each.

The more thing worth noting is how WPF handles window resize events. Because XAML uses various layout panels to describe the layout, resizing the window will cause its controls to assume new positions based on the panels they were placed in. With clever XAML manipulation, gone are the days of coding that OnResize event.

Finally, and this is more of a personal fancy that anything else, WPF seems to be better suited for applications that want to take advantage of some Windows Vista features. My favorite and most abused would be the Aero glass. Those who extend it with Windows Forms would know the kind of headaches you have to go though in order to put something that shiny glass you pulled out. That issue is gone with WPF.

Of course, nobody is saying WPF is perfect. I had to do a lot of head scratching before I could figure out threading and messaging in WPF (hint: Dispatcher). Microsoft seems to believe that threading is not needed for most implementations of WPF. Have them explain to me why my buttons locked up on my server application when I tried it without the threading.

Also, some useful and familiar controls from WinForms seem to have vanished into thin air, and the general consensus is that you have to "host" them in your WPF app. Ask me about that in a few days.

Still, WPF is in my opinion a step in the right direction away from Windows Forms, with its clear separation of UI design from program code, media rich capabilites and sheer awesomeness of getting some things done. If you are a .NET programmer, grab yourself a copy of Visual Studio 2008 (for excellent support -- express versions are available for free) and give it a shot.

I have a hunch that you won't be disappointed.