Data Binding in Code

At times, you may find that you need to bind the property of a control in the code behind. This is possible using the GetBindingExpression and SetBinding methods on the control.

To create a new binding and assign it to a control property, simply instantiate a Binding object (found in the System.Windows.Data namespace), assign the binding configuration to its properties as required, and apply the binding to the target control property using the control's SetBinding method. The SetBinding method requires you to pass it the Binding object and the dependency property identifier associated with the property to bind to on the target control, remembering that you can assign data bindings only to dependency properties.

For example, ...

Get Pro Business Applications with Silverlight 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.