Share via


Bind data to a property or element

This page applies to WPF and Silverlight 2

To bind data by using the Properties panel

  1. On the artboard, click the element in the layout that you want to create the binding on—this is where the data will flow into from the data source.

  2. In the Properties panel, click the Advanced property optionsCc294574.d6ba8f4a-b8a2-445a-af0b-a267dfade6e1(en-us,Expression.10).png button next to the property that you want to serve as the target for the binding—this is the specific property that will hold the data.

  3. In the pop-up menu, click Data Binding.

  4. In the Create Data Binding dialog box, do one of the following:

    • To bind to a field of a data source, click the Data Field button at the top of the dialog box. The list on the left side of the dialog box shows all the available data sources for the current document. As you change among the data sources in the list, the list on the right shows all the data fields for the selected data source. Select a data field in the list to serve as the binding source, and then click Finish.

    • To bind two properties of layout elements together, click the Element Property button at the top of the dialog box. The list on the left side of the dialog box shows all the available elements in the current document. As you change among the elements in the list, the list on the right side shows the properties for the selected element. Select a property in the list on the right to serve as the binding source, and then click Finish.

      Note

      Silverlight 2 does not support element-to-element binding.

    • To bind to an explicit data context, click the Explicit DataContext button at the top of the dialog box if a data context has been defined for the element that you are binding to. A single list will appear, showing all of the fields that are available for the current data context. Select a data field to serve as the source for the binding, and then click Finish.

Cc294574.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top

To bind data by dragging fields from the Project panel

  1. Under Data in the Project panel, click the data source field that you want to bind to, and then drag it onto the artboard. You can drag the data source field onto an empty part of the artboard or place it within an existing layout element.

  2. After you drag the data field into the desired location, a pop-up menu opens to prompt you to select the type of control to create to represent the data. If you drag the data source field over an existing element, you are also given the option to bind the data to that element.

  3. After selecting the type of control to use for the data, you will see the new control on the artboard. You are then prompted to select the property on that control to bind the data to. Select the property, and then click OK.

Note

By default, the property that is usually the most appropriate for the current control type is automatically selected, so in most cases you can just click OK to confirm the selection.

Cc294574.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top

See also

Concepts

Try it: Create and apply a value converter