I’ve been moving more and more into a XAML-based world lately. Between trainings and user group/conference talks, I’ve been digging into Silverlight and WPF and becoming more and more of a believer. My initial experience was pretty poor. I dragged controls onto the designer, created event handlers, and wondered what all of the fuss was about.
I’ve learned that there’s much more to XAML than what I’m used to from Windows forms. Instead of being based on events and event handlers, it’s all about declaring behaviors, actions, data bindings, and data presentation. This declarative world is a radical departure from the imperative forms world and requires a good amount of rethinking. The very ability to allow a designer to manage the user interface while the developer focuses on application logic is something long promised, but finally delivered.
I’ve taught a few three day classes on it, and tried to present to developers in hour-long user group sessions, but it’s never enough time! Part of the problem is that we’re used to taking collections of data and creating secondary objects for display, or creating formatted strings and stashing the data for subsequent lookups. Sometimes we would even create sub-classed controls to handle the data-specific issues. The way you present data using XAML/WPF/Silverlight is all based on more general declarations, is highly reusable, and makes it easy for designers to do their job without stepping on developer’s toes.
The main concepts for developers to understand include:
- Value Converters (formatters)
- Behaviors (modifications to controls at runtime)
- Actions (verbs)
- Triggers (events)
- Dependency Objects (nouns)
- Dependency Properties (adjectives)
Notice that custom controls aren’t in the list. It’s not that they never have a place – they certainly do sometimes – but fairly often you can accomplish everything that you need through the use of properties, behaviors, and styling/templating (typically performed by the designer).
In my next few posts, I’d like to go over these topics to give developers a look at how to structure their WPF/SL projects. This would be appropriate to developers who haven’t tried yet, or those who have tried but didn’t quite “get” the new paradigm.
Update (7/9): I forgot to add Triggers to the main concepts list!