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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access