O'Reilly logo

XAML Unleashed by Adam Nathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Binding in C#

The following translates the use of the Binding markup extension to C#, assuming the relevant Run is given the name run:

Binding binding = new Binding();// Set source objectbinding.Source = this.textBox;// Set source propertybinding.Path = new PropertyPath("Text");// Attach to target propertythis.run.SetBinding(Run.TextProperty, binding);

In C#, you can’t set run’s Text property to a Binding instance, because Text must be a string. The magic that is abstracted away by the markup extension in XAML is simply a call to run’s SetBinding method (inherited from FrameworkElement) that identifies which property to associate with the binding using the relevant static DependencyProperty property. This makes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required