BT

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

by Jonathan Allen on Jun 16, 2010 |

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.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT