Click to Rate and Give Feedback
Related Articles

This month we describe techniques for automating UI testing in Windows Presentation Foundation applications.

James McCaffrey

MSDN Magazine March 2009

...

Read more!

We show you how to create ink-enabled apps quickly with the Tablet PC SDK and the InkEdit and InkPicture ActiveX controls.

Gus Class

MSDN Magazine October 2008

...

Read more!

In this article we explain just how simple it can be to build a WPF application the right way using the MVVM Pattern.

Josh Smith

MSDN Magazine February 2009

...

Read more!

OMA Device Management (OMA-DM), based on a dialect of XML called SyncML, can be used to provision and manage mobile devices in an enterprise scenario. We'll show you how.

Ramon Arjona

MSDN Magazine February 2009

...

Read more!

Flow documents offer enormous flexibility in arranging text layout and pagination, but they don’t support data binding, so you can’t dynamically change content. Here we build a component to solve that problem.

Vincent Van Den Berghe

MSDN Magazine April 2009

...

Read more!

Also by this Author

Charles Petzold takes an inside look at the flexible bitmap pixel formats offered by the retained-mode graphics features of Windows Presentation Foundation.

Charles Petzold

MSDN Magazine June 2008

...

Read more!

This month Charles Petzold focuses on a very important part of the Viewport3D assemblage—the MeshGeometry3D class that defines the geometry of a 3D object in Windows Communication Foundation.

Charles Petzold

MSDN Magazine April 2007

...

Read more!

The presentation subsystem in the next version of Windows, code-named "Longhorn," offers powerful new capabilities to developers. This subsystem, code-named "Avalon," allows developers to take advantage of its capabilities through a new markup language code-named "XAML." In addition, modern object-oriented programming languages such as C# and Visual Basic .NET can be used to tie everything together. Because most applications written to Avalon will probably be a mix of XAML and programming code, this article discusses XAML tags used to control ...

Read more!

Charles Petzold

MSDN Magazine December 2005

...

Read more!

Here Charles Petzold explains several techniques for improving the performance of ItemsControls.

Charles Petzold

MSDN Magazine March 2009

...

Read more!

Popular Articles

Ray Djajadinata

MSDN Magazine May 2007

...

Read more!

Jason Clark

MSDN Magazine July 2003

...

Read more!

This article introduces 10 development tools that can increase your productivity, give you a better understanding of .NET, and maybe even change the way that you develop applications. The tools covered include NUnit to write unit tests, Reflector to examine assemblies, FxCop to police your code, Regulator to build regular expressions, NDoc to create code documentation and five more.

James Avery

MSDN Magazine July 2004

...

Read more!

Jeff Prosise explains when it's better to use UpdatePanel and when it's better to use asynchronous calls to WebMethods or page methods instead.

Jeff Prosise

MSDN Magazine June 2007

...

Read more!

A Sidebar gadget is a powerful little too that's surprisingly easy to create. Get in on the fun with Donavon West.

Donavon West

MSDN Magazine August 2007

...

Read more!

{End Bracket}
Let My People Code
Charles Petzold


In the 1920s, Hollywood was in trouble. Plagued by scandals and a general perception that the movies had gone too far in portraying sex and violence, there was a distinct danger that the government might step in. The studios responded by creating the Hays Office to police themselves and clean up the silver screen. The Hays Office established rules involving everything from proper language to appropriate displays of affection, and became the main arm of non-governmental censorship of the movies.
Movie writers and directors responded in the mid-1930s by finding creative ways around these restrictions. One such workaround was a new genre called the screwball comedy, which featured romance, slapstick, and wisecracks. There was little danger of lewd kissing in the screwball comedy-the romantic leads were often at odds for much of the movie. Even better, the dialogue was so fast and so hip that the censors couldn't even hear it. The result: classics such as It Happened One Night, Twentieth Century, and Bringing Up Baby-movies that would never have been conceived if writers and directors were free to do whatever their filthy minds desired.
Creativity often blossoms not when there is total freedom, but when severe restrictions limit the creator. Engineers as well as artists are familiar with this concept. When an oxygen tank exploded in Apollo 13 on its way to the moon, great creativity and ingenuity were required to make fixes. The creativity arose directly from the limited materials at hand.
I was reminded of this paradox recently while enjoying some of the most challenging and amusing programming I've ever done-and I wasn't even using a proper programming language! Lately, I've been getting my programming kicks with XAML, the Extensible Application Markup Language that forms a significant part of the Microsoft® Windows® Presentation Foundation.
XAML can access powerful classes in the Windows Presentation Foundation for performing layout and displaying graphics and animations. XAML can even be classified as a declarative programming language. But compared to more familiar programming languages, XAML is missing many basic programming features: There are no loops in XAML, no conditionals, and no way even to add or multiply numbers.
And yet, the more I restricted myself to XAML-only problem-solving-a state of existence I thought of as "living on Planet XAML"-the more creative I got. I realized that I could define composite graphics transforms in XAML that would essentially multiply matrices, thereby providing all the multiplication and addition I needed. And I found that I could simulate arrays in XAML by using a ListBox to hold multiple elements and then index those elements with data bindings.
My proudest achievement came with a XAML clock application. I wanted circular tick marks around the circumference of the clock. Customarily a clock has 12 large tick marks and 48 small tick marks, but without a for loop these tick marks would normally require 60 separate XAML elements. Alas, I just couldn't bring myself to create that much repetitive markup. I moaned over this problem for days until the breakthrough came. I could create precisely the tick marks I wanted by drawing two circles using dotted lines. Not only did it work, but I realized that I had done the job with just two graphics objects rather than the sixty most other clock applications required.
Writing XAML is fun. Writing XAML is challenging. Writing XAML is mind-expanding. But in some people's minds, writing XAML is an aberration. XAML is not supposed to be hand-written. As one Microsoft blogger put it, "XAML is for Tools," and over the months prior to its release, some XAML features have been removed because they were strictly for the benefits of humans rather than tools. Of course, XAML-generating tools such as Visual Studio® and Microsoft Expression® Interactive Designer may stimulate our aesthetic creativity, but they do nothing for our coding creativity.
Will future programmers even bother to learn XAML syntax? Or will they treat it as just "some weird XML stuff" that Visual Studio generates to save the layout of buttons and comboboxes?
Interactive designers and code generators certainly have their place in the modern programmer's arsenal. I'm sure they save lots of time. But let's not forget who we are. We are programmers. We are skilled in the art of writing powerful code. We get our kicks from using minimum code for maximum effect. We can make languages like XAML do things it was never intended to do. We can make it sing.


Charles Petzold is a contributing editor to MSDN Magazine and the author of Applications = Code + Markup: A Guide to the Microsoft Windows Presentation Foundation (Microsoft Press, 2006).

Page view tracker