Binding to a Collection

One of the most common uses of data binding is to bind the items of an items control to a collection. You might try to assign a Binding to an items control’s Items property, but, alas, Items is not a dependency property. All items controls expose a separate ItemsSource dependency property that exists specifically for data binding. Therefore, if you have a Windows Store app with a Page as follows:

<Page ...>  <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">    <GridView ItemsSource="{Binding}" />  </Grid></Page>

with the following code-behind that sets the data context to a simple array:

using Windows.UI.Xaml.Controls;namespace Chapter17 ...

Get XAML 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.