How to create a data binding for Windows Phone

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

A binding is a relationship between a UI property and a CLR object. There are several ways to create a binding object that defines a specific instance of a binding.

To create a binding in XAML

  1. Define the source object.

  2. Create a reference to the namespace of the source object in XAML.

  3. Create an instance of the source object in the Resources section.

  4. Bind to the source object by setting either the Source property or the DataContext property. The DataContext is inherited by all the element's children.

    -or-

To create a binding by using code

  1. Add the System.Windows.Data namespace

  2. Define the source object.

  3. Create the FrameworkElement you want to bind to.

  4. Create an instance of the source object

  5. Create a binding object.

  6. Set the binding properties on the binding object.

  7. Set the source of the binding by setting either the Source property or the DataContext property. The DataContext is inherited by all the element's children.

    -or-

  8. Attach the binding to the property of the FrameworkElement.

See Also

Reference

Binding

Other Resources

Data binding for Windows Phone 8