Populating a Pivot Via a Data Bound Collection

This second example looks at using a collection of viewmodels to dynamically populate a Pivot using a DataTemplate. The result of this example is the same as the previous example, except in this case the PivotItems are dynamically created based on their data type. This provides some added flexibility that can be useful in larger apps.

The example code for this section is located in the files DataboundPivotView.xaml, DataboundPivotView.xaml.cs, and DataboundPivotViewModel.cs in the downloadable sample code.

In this example the viewmodel has been changed from exposing two child viewmodel properties to a collection of viewmodels (see Listing 11.5).

LISTING 11.5. DataboundPivotViewModel Class

Get Windows® Phone 8 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.