TreeView

As defined by the W3C:

A tree view widget presents a hierarchical list. Any item in the hierarchy may have child items, and items that have children may be expanded or collapsed to show or hide the children. For example, in a file system navigator that uses a tree view to display folders and files, an item representing a folder can be expanded to reveal the contents of the folder, which may be files, folders, or both.

<FluentTreeView> wraps the <fluent-tree-view> element, a web component implementation of a tree view leveraging the Fluent UI design system. It uses the <FluentTreeItem> component to define the nodes.

NOTE: When construction a tree by specifying FluentTreeItem components, an item can not be deselected by setting the SelectedItem parameter value to null. This only works when using the Items collection.

When using a TreeView with dynamic items, always use th Items collection to define the tree structure. The FluentTreeItem component should only be used to define the tree nodes when the tree structure is static.

Examples

Default with event handling

Example

Current selected tree item is

Most recently expanded/collapsed tree item is

Download: 

Dynamic tree generation via Items

Example
Total items: 123320
Selected item: Item 29854
Download: 

Multi-select

Example
Selected items:
Download: 

With Unlimited Items

Example
Selected Item:
Download: 

Flat tree

Example
Download: 

Some expanded

Example
Root item Flowers
Download: 

Pre-selected tree item

Example
Root item Planes
Download: 

Disabled tree item

Example
Root item Flowers Planes
Download: 

With several nested items (expanded)

Example
Root item Nested Root item 1
Download: 

With data binding

Example
Flowers Planes

Expanded

Flowers expanded Planes expanded

Selected

Daisy selected Sunflower selected Rose selected
Download: 

Documentation

FluentTreeView Class

Parameters

Name
Type
Default
Description
ChildContentRenderFragment?
Gets or sets the content to be rendered inside the component.
CurrentSelectedFluentTreeItem?
Gets or sets the currently selected tree item
ItemsIEnumerable<ITreeViewItem>?
Gets or sets the list of items to bind to the tree.
ItemTemplateRenderFragment<ITreeViewItem>?
Gets or sets the template for rendering tree items.
LazyLoadItemsbool
False
Can only be used when the FluentTreeView.Items is defined.
Gets or sets whether the tree should use lazy loading when expanding nodes.
If True, the tree will only render the children of a node when it is expanded and will remove them when it is collapsed.
RenderCollapsedNodesbool
False
Gets or sets whether the tree should render nodes under collapsed items
Defaults to false
SelectedItemITreeViewItem?
Gets or sets the currently selected tree item.
Only when using the FluentTreeView.Items property.

EventCallbacks

Name
Type
Description
CurrentSelectedChangedEventCallback<FluentTreeItem>
Called when FluentTreeView.CurrentSelected changes.
You cannot update FluentTreeItem properties.
OnExpandedChangeEventCallback<FluentTreeItem>
Called whenever FluentTreeItem.Expanded changes on an
item within the tree.
You cannot update FluentTreeItem properties.
OnSelectedChangeEventCallback<FluentTreeItem>
Called whenever FluentTreeItem.Selected changes on an
item within the tree.
You cannot update FluentTreeItem properties.
SelectedItemChangedEventCallback<ITreeViewItem>
Called when FluentTreeView.SelectedItem changes.
Only when using the FluentTreeView.Items property.

FluentTreeItem Class

Parameters

Name
Type
Default
Description
ChildContentRenderFragment?
Gets or sets the content to be rendered inside the component.
Collapsedbool
True
Returns true if the tree item is collapsed,
and false if expanded.
Disabledbool
False
When true, the control will be immutable by user interaction. See disabled HTML attribute for more information.
Expandedbool
False
Returns true if the tree item is expanded,
and false if collapsed.
IconCollapsedIcon?
Gets or sets the Icon displayed at the start of tree item,
when the node is collapsed.
If this icon is not set, the FluentTreeItem.IconExpanded will be used.
IconExpandedIcon?
Gets or sets the Icon displayed at the start of tree item,
when the node is expanded.
If this icon is not set, the FluentTreeItem.IconCollapsed will be used.
InitiallyExpandedbool
False
If set to true then the tree item will
be expanded when it is created.
InitiallySelectedbool
False
If set to true then the tree item will
be selected when it is created.
ItemsIEnumerable<ITreeViewItem>?
Gets or sets the list of sub-items to bind to the tree item
Selectedbool
False
When true, the control will appear selected by user interaction.
Textstring?
Gets or sets the text of the tree item

EventCallbacks

Name
Type
Description
ExpandedChangedEventCallback<bool>
Called whenever FluentTreeItem.Expanded changes.
SelectedChangedEventCallback<bool>
Called whenever FluentTreeItem.Selected changes.
An error has occurred. This application may no longer respond until reloaded. Reload 🗙