WPF Binding Expression Alternatives

Philipp Sumi creates a custom binding/markup extension with an example where he’s added a “lookup” key to the text field.

A base class for custom WPF binding markup extensions

Nigel Spencer writes some code which allows him to attribute a data class with validation rules such as maximum length. I like the style of putting some basic data rules on the data object rather than spreading the rules around the user interface.

Applying MetaData to WPF Bindings

This style would require diligence on the part of the developer and UI designer to be certain that all of the various input methods (controls) are covered, and that the markup extension is used consistently.

I’d like to see a solution which didn’t rely on a custom markup extension if possible. Maybe an attached property or something … (my style is to try to use built-in stuff as much as possible for training, learn-ability, tool support, etc).


  1. Attached properties are a viable and often preferable alternative to markup extensions (as a matter of fact, the lookup example at hardcodet.net could be implemented that easily with an AP that I even mentioned it). You rarely need to mess with markup extensions, but they can come in handy. I’m thinking about simplified XAML (a lot of controls that use the same bindings, converters etc.) and scenarios where you would have to use several attached properties (which might cause you headache when it comes to state management). Apart from that, I’d say you probably know that you need an extension if all alternatives just suck :).

Comments are closed.