Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-create-simple-or-complex-treeviews.md
Andy De George da363692ff Initial WPF content migrated (#17)
* 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
2020-09-04 09:46:28 -07:00

3.2 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
How to: Create Simple or Complex TreeViews 03/30/2017
TreeView control [WPF], creating
Control class [WPF], TreeView [WPF], creating
1defbb78-b8e7-4c0e-b650-576453ac828d

How to: Create Simple or Complex TreeViews

This example shows how to create simple or complex xref:System.Windows.Controls.TreeView controls.

A xref:System.Windows.Controls.TreeView consists of a hierarchy of xref:System.Windows.Controls.TreeViewItem controls, which can contain simple text strings and also more complex content, such as xref:System.Windows.Controls.Button controls or a xref:System.Windows.Controls.StackPanel with embedded content. You can explicitly define the xref:System.Windows.Controls.TreeView content or a data source can provide the content. This topic provides examples of these concepts.

Example

The xref:System.Windows.Controls.HeaderedItemsControl.Header%2A property of the xref:System.Windows.Controls.TreeViewItem contains the content that the xref:System.Windows.Controls.TreeView displays for that item. A xref:System.Windows.Controls.TreeViewItem can also have xref:System.Windows.Controls.TreeViewItem controls as its child elements and you can define these child elements by using the xref:System.Windows.Controls.ItemsControl.Items%2A property.

The following example shows how to explicitly define xref:System.Windows.Controls.TreeViewItem content by setting the xref:System.Windows.Controls.HeaderedItemsControl.Header%2A property to a text string.

[!code-xamlTreeViewSimple#1]

The following example show how to define child elements of a xref:System.Windows.Controls.TreeViewItem by defining xref:System.Windows.Controls.ItemsControl.Items%2A that are xref:System.Windows.Controls.Button controls.

[!code-xamlTreeViewSimple#3]

The following example shows how to create a xref:System.Windows.Controls.TreeView where an xref:System.Windows.Data.XmlDataProvider provides xref:System.Windows.Controls.TreeViewItem content and a xref:System.Windows.HierarchicalDataTemplate defines the appearance of the content.

[!code-xamlTreeViewSimple#6]

[!code-xamlTreeViewSimple#7]

[!code-xamlTreeViewSimple#5]

The following example shows how to create a xref:System.Windows.Controls.TreeView where the xref:System.Windows.Controls.TreeViewItem content contains xref:System.Windows.Controls.DockPanel controls that have embedded content.

[!code-xamlTreeViewSimple#9]

See also