WPF Databinding

I find the tutorial videos at Windows Client .Net equally awesome. Dot Net Rocks TV has also covered it some time ago.


The best resource I've found for WPF data binding is Bea Costa's blog. Start from the first post and read forward. It's awesome.


in code behind -- set the DataContext of your list box equal to the collection you're binding to.

private void OnInit(object sender, EventArgs e)
{
  //myDataSet is some IEnumerable 

  // myListBox is a ListBox control.
  // Set the DataContext of the ListBox to myDataSet
  myListBox.DataContext = myDataSet;
}

In XAML, Listbox can declare which properties it binds to using the "Binding" syntax.

<ListBox Name="myListBox" Height="200"
  ItemsSource="{Binding Path=BookTable}"
  ItemTemplate  ="{StaticResource BookItemTemplate}"/>