WPF Image Viewer Part 3, Data Binding to a List Box

This is a part of the WPF image viewer tutorial: Introduction, Part 1, Part2.

In this part we'll connect the C# code with the XAML UI, just open Window1.xaml, find the Grid element and add the following line between <Grid> and </Grid>

<ListBox ItemsSource="{Binding AllImages}"/>

This will create a list box and bind it's ItemsSource property to the AllImages property we wrote in the last part, it you'll run this you will get a window with a list box covering the entire window and the list box showing the names of all the image files.

The reason we set the DataContext in the code is just to save us the little extra work of specifying where to get AllImages from (the default is from the DataContext).

This is how easy it is to databind just about anything in WPF, in the next part we'll do some more data binding and get our image viewer to actually view images.

posted @ Monday, August 20, 2007 12:54 PM

Comments on this entry:

No comments posted yet.

Your comment:

 (will not be displayed)

Please add 2 and 7 and type the answer here: