* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
2.8 KiB
title, ms.date, helpviewer_keywords, ms.assetid
| title | ms.date | helpviewer_keywords | ms.assetid | ||
|---|---|---|---|---|---|
| How to: Use the Master-Detail Pattern with Hierarchical Data | 03/30/2017 |
|
11429b9e-058d-4084-bfb6-2cf209c8ddf7 |
How to: Use the Master-Detail Pattern with Hierarchical Data
This example shows how to implement the master-detail scenario.
Example
In this example, LeagueList is a collection of Leagues. Each League has a Name and a collection of Divisions, and each Division has a name and a collection of Teams. Each Team has a team name.
[!code-xamlMasterDetail#HowTo1]
[!code-xamlMasterDetail#HowTo2]
The following is a screenshot of the example. The Divisions xref:System.Windows.Controls.ListBox automatically tracks selections in the Leagues xref:System.Windows.Controls.ListBox and display the corresponding data. The Teams xref:System.Windows.Controls.ListBox tracks selections in the other two xref:System.Windows.Controls.ListBox controls.
The two things to notice in this example are:
-
The three xref:System.Windows.Controls.ListBox controls bind to the same source. You set the xref:System.Windows.Data.Binding.Path%2A property of the binding to specify which level of data you want the xref:System.Windows.Controls.ListBox to display.
-
You must set the xref:System.Windows.Controls.Primitives.Selector.IsSynchronizedWithCurrentItem%2A property to
trueon the xref:System.Windows.Controls.ListBox controls of which the selection you are tracking. Setting this property ensures that the selected item is always set as the xref:System.Windows.Controls.ItemCollection.CurrentItem%2A. Alternatively, if the xref:System.Windows.Controls.ListBox gets it data from a xref:System.Windows.Data.CollectionViewSource, it synchronizes selection and currency automatically.
The technique is slightly different when you are using XML data. For an example, see Use the Master-Detail Pattern with Hierarchical XML Data.
