September 04, 2006

WPF- Data Binding

Data binding

  • Data templates are used to specify how a control must display an object.

  • Data templates act as a bridge between objects and the user interface, and give designers great flexibility to manage data presentation.


This example shows how to bind XML data island with text.

<Page x:Class="TestXBAP.Page1"



Title="Page1" Height="170.4" Width="354.4">


<XmlDataProvider x:Key="EmployeeData" XPath="/Employees/Employee">


<!-- xml data island -->

<Employees xmlns="">

<Employee Name="Bill Gates" DOB="13-Jul-1973">







<!-- binding to data island -->

<StackPanel DataContext="{StaticResource EmployeeData}">

<TextBlock Text="{Binding XPath=@Name}" FontSize="20" />

<TextBlock Text="{Binding XPath=@DOB}" FontSize="10" />

<TextBlock Text="{Binding XPath=Title/text()}" FontSize="10" />