O'Reilly logo

Microsoft Visual Studio 2015 Unleashed, Third Edition by Mike Snell, Lars Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

<Window.Resources>   <DataTemplate x:Key="ImageDataTemplate">      <Image Source="{Binding ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required