TreeView
A TreeView is a vertically scrollable area that links to, and displays, a list of items organized in a tree.
Read time 11 minutesLast updated 2 days ago
Definition
- Type: Class
- Namespace: UnityEngine.UIElements
- Assembly: UnityEngine.UIElementsModule
- Inherits from: BaseTreeView
- Implements: IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IBindable, ISerializationCallbackReceiver
public class TreeView : BaseTreeView, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IBindable, ISerializationCallbackReceiver
Remarks
A TreeView is a ScrollView with additional logic to display a tree of vertically-arranged VisualElements. Each VisualElement in the tree is bound to a corresponding element in a data-source list. The data-source list can contain elements of any type.
The logic required to create VisualElements, and to bind them to or unbind them from the data source, varies depending on the intended result. It's up to you to implement logic that is appropriate to your use case. For the ListView to function correctly, you must supply at least the following:
It is also recommended to supply the following for more complex items:
- TreeView.makeItem
- TreeView.bindItem
- BaseVerticalCollectionView.fixedItemHeight, in the case of ListView
FixedHeight
The TreeView creates VisualElements for the visible items, and supports binding many more. As the user scrolls, the TreeView recycles VisualElements and re-binds them to new data items.
For more information, refer to UXML element TreeView.
Constructors
Constructor | Description |
|---|---|
| TreeView() | Creates a TreeView with all default properties. |
| TreeView(System.Func{UnityEngine.UIElements.VisualElement},System.Action{UnityEngine.UIElements.VisualElement,System.Int32}) | Creates a TreeView with specified factory methods. |
| TreeView(System.Int32,System.Func{UnityEngine.UIElements.VisualElement},System.Action{UnityEngine.UIElements.VisualElement,System.Int32}) | Creates a TreeView with specified factory methods using the fixed height virtualization method. |
Properties
Property | Description |
|---|---|
| bindItem | Callback for binding a data item to the visual element. |
| destroyItem | Callback invoked when a VisualElement created via TreeView.makeItem is no longer needed and will be destroyed. |
| itemTemplate | A UXML template that constructs each recycled and rebound element within the tree. This template is designed to replace the TreeView.makeItem definition. |
| makeItem | Callback for constructing the VisualElement that is the template for each recycled and re-bound element in the list. |
| unbindItem | Callback for unbinding a data item from the VisualElement. |
| viewController | The view controller for this view, cast as a TreeViewController. |