3 Working with Form Controls. This chapter contains the following topics: Section 3.1, 'Understanding Form Controls'. Use parent child controls to present a hierarchical grid view or a tree view. Data Item Information: Check Box Combo Box. Radio Button.
- Live Help
- Components
Component Categories
Component Types
- .NET Components
Component Environments
Component Publishers
- Applications
Application Categories
Application Types
Application Publishers
- Add-ins
Add-in Categories
Add-in Types
Add-in Publishers
- Cloud Services If you have a Cloud Service / API relevant to our global audience of Application Developers and IT Professionals, then get in touch. Every day, customers are searching our web site for software solutions to solve specific IT problems.Join Our Program and start working with us today!
- Brands
Bestselling Brands
Note Also see the Master/detail sample.
You can make a multi-level master/details (also known as list-details) view of hierarchical data by binding items controls to CollectionViewSource instances that are bound together in a chain. In this topic we use the {x:Bind} markup extension where possible, and the more flexible (but less performant) {Binding} markup extension where necessary.
One common structure for Universal Windows Platform (UWP) apps is to navigate to different details pages when a user makes a selection in a master list. This is useful when you want to provide a rich visual representation of each item at every level in a hierarchy. Another option is to display multiple levels of data on a single page. This is useful when you want to display a few simple lists that let the user quickly drill down to an item of interest. This topic describes how to implement this interaction. The CollectionViewSource instances keep track of the current selection at each hierarchical level.
We'll create a view of a sports team hierarchy that is organized into lists for leagues, divisions, and teams, and includes a team details view. When you select an item from any list, the subsequent views update automatically.
Prerequisites
This topic assumes that you know how to create a basic UWP app. For instructions on creating your first UWP app, see Create your first UWP app using C# or Visual Basic.
Create the project
Create a new Blank Application (Windows Universal) project. Name it 'MasterDetailsBinding'.
Create the data model
Add a new class to your project, name it ViewModel.cs, and add this code to it. This will be your binding source class.
Create the view
Next, expose the binding source class from the class that represents your page of markup. We do that by adding a property of type LeagueList to MainPage.
Finally, replace the contents of the MainPage.xaml file with the following markup, which declares three CollectionViewSource instances and binds them together in a chain. The subsequent controls can then bind to the appropriate CollectionViewSource, depending on its level in the hierarchy.
Note that by binding directly to the CollectionViewSource, you're implying that you want to bind to the current item in bindings where the path cannot be found on the collection itself. There's no need to specify the CurrentItem property as the path for the binding, although you can do that if there's any ambiguity. For example, the ContentControl representing the team view has its Content property bound to the
Teams
CollectionViewSource. However, the controls in the DataTemplate bind to properties of the Team
class because the CollectionViewSource automatically supplies the currently selected team from the teams list when necessary.