Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Karl Shifflett Shows How to make VS 2010’s Binding Builder Actually Work

Karl Shifflett Shows How to make VS 2010’s Binding Builder Actually Work

This item in japanese

Visual Studio 2010 comes with a feature they call the “Binding Builder”. This tool, launched from the properties pane, helps developers quickly construct XAML bindings for WPF and Silverlight. But without some help, it doesn’t work when the data context is only set at runtime.

Karl explains the problem comes down to a lack of information. The IDE has no way of knowing what type of object is going to be bound to the data-context, which in turn means it can’t examine the bindings for errors. The work-around is quite simple; just give it a data-context that is only used at design time.

To do this you need to add a “d:DataContext” property to the same object that will get the real data context. When the IDE sees both a normal and a design-time data-context it will use the design-time one. To further facilitate this design is the addition of the “d:DesignInstance” markup extension. This will create a fake type with the same properties as the indicated type, allowing classes to be used even if they don’t have a default constructor.

For more information on the Binding Builder and design-time markup extensions, see Karl’s post on the WPF and Silverlight Designer blog.

Rate this Article