views:

21

answers:

1

I have successfully created my data source, which is a CLR object of the class Person. Person class has a bunch of public properties, such as Name, Emails, Phones, etc. I want to data bind person's emails (there's more than one email) to DataGrid or ListBox controls.

I want to be able to choose which fields of the email I want to show (email has properties ID, email, and email type). If I just data bind ItemsSource property:

  • for DataGrid - all properties get binded (and I want to skip the ID property)
  • for ListBox - only the email value is seen, so email type is missing.

How can I make it right using Microsoft Expression Blend? I have the latest version 4 if it matters to anyone. Thanks very much!

A: 

Click on the little box to the right of the ItemsSource property for the DataGrid or ListBox in Blend and choose "Data Binding..."

If Blend can figure out the data type that your are using as a DataContext, then you can select your collection from the "Data Context" tab. If Blend doesn't know, then you choose "Use a custom path expression" and type in the name of the property to bind to.

Hope this helps, B

Brian Genisio
Thanks for you answer Brian. The thing is, I already did what you wrote. My problem is that I can't choose which of the email properties I want to show. Following your instructions my DataGrid shows all email properties, i.e. ID, email value and email type. I want to choose which of those I want to show.
Boris
Gotcha... So, for ListBoxes, the data context gets bound, and you need to give it a template that binds to properties on the individual items.In the case of the DataGrid, you have two options: the first is the default auto-generation of columns. If you want control over the specific columns to show, you have to declare it. Check this out: http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-datagrid-feature-walkthrough.aspx
Brian Genisio
OK, excellent. Thanks for all the help Brian.
Boris