Binding to the Images

Because our earlier trick of overriding ToString won’t give us the right data presentation (an image, after all, is not a string), we need to turn to data templates. The DataTemplate class is used to tell a control specifically how you want its data to be displayed. By using a data template within the visual tree of the control, you have complete freedom to present the bound data in any fashion you want.

For this application, we are looking for images in the ListBox. This turns out to be quite easy. Create a Window1.Resources element in XAML, and create a DataTemplate that sets up the exact visualization we need:

image

Then assign ...

Get Microsoft® Visual Studio® 2010 Unleashed 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.