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 theSelectedItem
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
Current selected tree item is
Most recently expanded/collapsed tree item is
Dynamic tree generation via Items
Multi-select
With Unlimited Items
Flat tree
Some expanded
Pre-selected tree item
Disabled tree item
With several nested items (expanded)
With data binding
Expanded
Selected
Documentation
FluentTreeView Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
ChildContent | RenderFragment? | Gets or sets the content to be rendered inside the component. | |
CurrentSelected | FluentTreeItem? | Gets or sets the currently selected tree item | |
Items | IEnumerable<ITreeViewItem>? | Gets or sets the list of items to bind to the tree. | |
ItemTemplate | RenderFragment<ITreeViewItem>? | Gets or sets the template for rendering tree items. | |
LazyLoadItems | bool | 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. |
RenderCollapsedNodes | bool | False | Gets or sets whether the tree should render nodes under collapsed items Defaults to false |
SelectedItem | ITreeViewItem? | Gets or sets the currently selected tree item. Only when using the FluentTreeView.Items property. |
EventCallbacks
Name | Type | Description |
---|---|---|
CurrentSelectedChanged | EventCallback<FluentTreeItem> | Called when FluentTreeView.CurrentSelected changes.You cannot update FluentTreeItem properties. |
OnExpandedChange | EventCallback<FluentTreeItem> | Called whenever FluentTreeItem.Expanded changes on anitem within the tree. You cannot update FluentTreeItem properties. |
OnSelectedChange | EventCallback<FluentTreeItem> | Called whenever FluentTreeItem.Selected changes on anitem within the tree. You cannot update FluentTreeItem properties. |
SelectedItemChanged | EventCallback<ITreeViewItem> | Called when FluentTreeView.SelectedItem changes.Only when using the FluentTreeView.Items property. |
FluentTreeItem Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
ChildContent | RenderFragment? | Gets or sets the content to be rendered inside the component. | |
Collapsed | bool | True | Returns true if the tree item is collapsed,and false if expanded. |
Disabled | bool | False | When true, the control will be immutable by user interaction. See disabled HTML attribute for more information. |
Expanded | bool | False | Returns true if the tree item is expanded,and false if collapsed. |
IconCollapsed | Icon? | 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. | |
IconExpanded | Icon? | 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. | |
InitiallyExpanded | bool | False | If set to true then the tree item willbe expanded when it is created. |
InitiallySelected | bool | False | If set to true then the tree item willbe selected when it is created. |
Items | IEnumerable<ITreeViewItem>? | Gets or sets the list of sub-items to bind to the tree item | |
Selected | bool | False | When true, the control will appear selected by user interaction. |
Text | string? | Gets or sets the text of the tree item |
EventCallbacks
Name | Type | Description |
---|---|---|
ExpandedChanged | EventCallback<bool> | Called whenever FluentTreeItem.Expanded changes. |
SelectedChanged | EventCallback<bool> | Called whenever FluentTreeItem.Selected changes. |