Binding to a collection

The previous recipe showed how to bind various properties to a single object, using single data controls, such as TextBlock, TextBox, or Button. Some controls, however, are capable of displaying multiple object data, such as a ListBox. These controls can bind to a collection of data objects, and with the help of data templates and value converters (to be covered in later recipes), become a powerful visualization tool. Let's examine the basic ideas of binding to collection of objects.

Getting ready

Make sure Visual Studio is up and running.

How to do it...

We'll create a collection of Person object and bind them to a ListBox, showing the details we need to take care of.

  1. Create a new WPF Application named CH06.BindingToCollection ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.