TreeView Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a hierarchical list with expanding and collapsing nodes that contain nested items.
This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces).
/// [Microsoft.UI.Xaml.MUXContractProperty(version=6)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Version(1)]
class TreeView : Control
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Version(1)]
/// [Microsoft.UI.Xaml.CustomAttributes.MUXContractProperty(version=6)]
/// [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallbackMethodName(value="OnPropertyChanged")]
class TreeView : Control
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallbackMethodName(value="OnPropertyChanged")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.XamlContract, 65536)]
class TreeView : Control
[Microsoft.UI.Xaml.MUXContractProperty(version=6)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Version(1)]
public class TreeView : Control
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Version(1)]
[Microsoft.UI.Xaml.CustomAttributes.MUXContractProperty(version=6)]
[Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallbackMethodName(value="OnPropertyChanged")]
public class TreeView : Control
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallbackMethodName(value="OnPropertyChanged")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.XamlContract), 65536)]
public class TreeView : Control
Public Class TreeView
Inherits Control
- Inheritance
-
TreeView
- Attributes
-
Microsoft.UI.Xaml.MUXContractPropertyAttribute MarshalingBehaviorAttribute ThreadingAttribute VersionAttribute Microsoft.UI.Xaml.CustomAttributes.MUXContractPropertyAttribute Microsoft.UI.Xaml.CustomAttributes.MUXPropertyChangedCallbackMethodNameAttribute ContractVersionAttribute
Examples
Tip
For more info, design guidance, and code examples, see Tree view.
The WinUI 2 Gallery app includes interactive examples of most WinUI 2 controls, features, and functionality. Get the app from the Microsoft Store or get the source code on GitHub.
Remarks
Control style and template
You can modify the default Style and ControlTemplate to give the control a unique appearance. For information about modifying a control's style and template, see XAML styles. The default style, template, and resources that define the look of the control are included in the generic.xaml
file. For design purposes, generic.xaml
is installed with the WinUI (Microsoft.UI.Xaml) NuGet package. By default, this location is \Users\<username>\.nuget\packages\microsoft.ui.xaml\<version>\lib\uap10.0\Microsoft.UI.Xaml\Themes\generic.xaml
. Styles and resources from different versions of WinUI might have different values.
XAML also includes resources that you can use to modify the colors of a control in different visual states without modifying the control template (modifying these resources is preferred to setting properties). For more info, see the Light-weight styling section of the XAML styles article.
Constructors
TreeView() |
Initializes a new instance of the TreeView control. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
Properties
CanDragItems |
Gets or sets a value that indicates whether items in the view can be dragged as data payload. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
CanDragItemsProperty |
Identifies the CanDragItems dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
CanReorderItems |
Gets or sets a value that indicates whether items in the view can be reordered through user interaction. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
CanReorderItemsProperty |
Identifies the CanReorderItems dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemContainerStyle |
Gets or sets the style that is used when rendering the item containers. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemContainerStyleProperty |
Identifies the ItemContainerStyle dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemContainerStyleSelector |
Gets or sets a reference to a custom StyleSelector logic class. The StyleSelector returns different Style values to use for the item container based on characteristics of the object being displayed. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemContainerStyleSelectorProperty |
Identifies the ItemContainerStyleSelector dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemContainerTransitions |
Gets or sets the collection of Transition style elements that apply to the item containers of a TreeView. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemContainerTransitionsProperty |
Identifies the ItemContainerTransitions dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemsSource |
Gets or sets an object source used to generate the content of the TreeView. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemsSourceProperty |
Identifies the ItemsSource dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemTemplate |
Gets or sets the DataTemplate used to display each item. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemTemplateProperty |
Identifies the ItemTemplate dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemTemplateSelector |
Gets or sets a reference to a custom DataTemplateSelector logic class. The DataTemplateSelector referenced by this property returns a template to apply to items. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemTemplateSelectorProperty |
Identifies the ItemTemplateSelector dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
RootNodes |
Gets or sets the collection of root nodes of the tree. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
SelectedItem |
Gets or sets the SelectedItem property of a TreeView. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
SelectedItemProperty |
Identifies the SelectedItem dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
SelectedItems |
Gets the currently selected items. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
SelectedNode |
Gets or sets the node that is selected in the tree. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
SelectedNodes |
Gets or sets the collection of nodes that are selected in the tree. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
SelectionMode |
Gets or sets the selection behavior for a TreeView instance. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
SelectionModeProperty |
Identifies the SelectionMode dependency property. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
Methods
Collapse(TreeViewNode) |
Collapses the specified node in the tree. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ContainerFromItem(Object) |
Returns the container corresponding to the specified item. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ContainerFromNode(TreeViewNode) |
Returns the container corresponding to the specified node. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
Expand(TreeViewNode) |
Expands the specified node in the tree. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemFromContainer(DependencyObject) |
Returns the item that corresponds to the specified, generated container. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
NodeFromContainer(DependencyObject) |
Returns the TreeViewNode corresponding to the specified container. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
SelectAll() |
Selects all nodes in the tree. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
Events
Collapsed |
Occurs when a node in the tree is collapsed. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
DragItemsCompleted |
Occurs when a drag operation that involves one of the items in the view is ended. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
DragItemsStarting |
Occurs when a drag operation that involves one of the items in the view is initiated. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
Expanding |
Occurs when a node in the tree starts to expand. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
ItemInvoked |
Occurs when an item in the tree is invoked. This documentation applies to WinUI 2 for UWP (for WinUI in the Windows App SDK, see the Windows App SDK namespaces). |
SelectionChanged |