Table of Contents

Class MudTreeView<T>

Namespace
MudBlazor
Assembly
MudBlazor.dll

An extensively customizable tree view component for displaying hierarchical data, featuring item selection, lazy-loading, and templating support.

[CascadingTypeParameter("T")]
public class MudTreeView<T> : MudComponentBase, IComponent, IHandleEvent, IHandleAfterRender, IMudStateHasChanged

Type Parameters

T

The type of item to display.

Inheritance
MudTreeView<T>
Implements
Inherited Members
Extension Methods

Constructors

MudTreeView()

public MudTreeView()

Properties

AutoExpand

Automatically expands items to show selected children.

[Parameter]
[Category("Selecting")]
public bool AutoExpand { get; set; }

Property Value

bool

Remarks

Defaults to false.

AutoSelectParent

Automatically checks an item if all children are selected.

[Parameter]
[Category("Selecting")]
public bool AutoSelectParent { get; set; }

Property Value

bool

Remarks

Defaults to true. Only applies when SelectionMode is MultiSelection. Items will also be deselected if any children are deselected.

CheckBoxColor

The color of checkboxes.

[Parameter]
[Category("Selecting")]
public Color CheckBoxColor { get; set; }

Property Value

Color

Remarks

Defaults to Default. Only applies when SelectionMode is MultiSelection.

CheckedIcon

The icon displayed for checked items.

[Parameter]
[Category("Selecting")]
public string CheckedIcon { get; set; }

Property Value

string

Remarks

Defaults to CheckBox.

ChildContent

The content within this component.

[Parameter]
[Category("Data")]
public RenderFragment? ChildContent { get; set; }

Property Value

RenderFragment

Remarks

Applies when ItemTemplate and Items are both not set.

Classname

protected string Classname { get; }

Property Value

string

Color

The color of the selected item.

[Parameter]
[Category("Selecting")]
public Color Color { get; set; }

Property Value

Color

Remarks

Defaults to Primary.

Comparer

The comparer used to check if two items are equal.

[Parameter]
[Category("Selecting")]
public IEqualityComparer<T?> Comparer { get; set; }

Property Value

IEqualityComparer<T>

Dense

Uses compact vertical padding.

[Parameter]
[Category("Appearance")]
public bool Dense { get; set; }

Property Value

bool

Remarks

Defaults to false.

Disabled

Prevents the user from interacting with any items.

[Parameter]
[Category("Behavior")]
public bool Disabled { get; set; }

Property Value

bool

Remarks

Defaults to false.

ExpandOnClick

Expands an item with children if it is clicked anywhere (not just the expand/collapse buttons).

[Parameter]
[Category("Click action")]
public bool ExpandOnClick { get; set; }

Property Value

bool

Remarks

Defaults to false.

ExpandOnDoubleClick

Expands an item with children if it is double-clicked anywhere (not just the expand/collapse buttons).

[Parameter]
[Category("Click action")]
public bool ExpandOnDoubleClick { get; set; }

Property Value

bool

Remarks

Defaults to false.

FilterFunc

Determines whether items are displayed.

[Parameter]
[Category("Behavior")]
public Func<TreeItemData<T>, Task<bool>>? FilterFunc { get; set; }

Property Value

Func<TreeItemData<T>, Task<bool>>

Remarks

Defaults to null. The function provides an item and should return true to display the item, or false to hide it.

Height

Sets a fixed height.

[Parameter]
[Category("Appearance")]
public string? Height { get; set; }

Property Value

string

Remarks

Defaults to null. Can be a CSS value such as 500px or 30%. When set, items can be scrolled vertically. Otherwise, the height will grow automatically.

Hover

Shows an effect when items are hovered over.

[Parameter]
[Category("Appearance")]
public bool Hover { get; set; }

Property Value

bool

Remarks

Defaults to false.

IndeterminateIcon

The icon displayed for indeterminate items.

[Parameter]
[Category("Selecting")]
public string IndeterminateIcon { get; set; }

Property Value

string

Remarks

Defaults to IndeterminateCheckBox. Only applies when TriState is true.

ItemTemplate

The template for rendering each item.

[Parameter]
[Category("Data")]
public RenderFragment<TreeItemData<T>>? ItemTemplate { get; set; }

Property Value

RenderFragment<TreeItemData<T>>

Items

The items being displayed.

[Parameter]
[Category("Data")]
public IReadOnlyCollection<TreeItemData<T>>? Items { get; set; }

Property Value

IReadOnlyCollection<TreeItemData<T>>

MaxHeight

Sets a maximum height.

[Parameter]
[Category("Appearance")]
public string? MaxHeight { get; set; }

Property Value

string

Remarks

Defaults to null. Can be a CSS value such as 500px or 30%. When set, items can be scrolled vertically. Otherwise, the height will grow automatically.

ReadOnly

Prevents selections from being changed.

[Parameter]
[Category("Selecting")]
public bool ReadOnly { get; set; }

Property Value

bool

Remarks

Defaults to false. When true, selections cannot be changed, but the current selections will continue to be displayed.

Ripple

Shows a ripple effect when an item is clicked.

[Parameter]
[Category("Appearance")]
public bool Ripple { get; set; }

Property Value

bool

Remarks

Defaults to true.

SelectedValue

The currently selected value.

[Parameter]
[Category("Selecting")]
public T? SelectedValue { get; set; }

Property Value

T

Remarks

Applies when SelectionMode is SingleSelection.

SelectedValueChanged

Occurs when SelectedValue has changed.

[Parameter]
public EventCallback<T?> SelectedValueChanged { get; set; }

Property Value

EventCallback<T>

SelectedValues

The currently selected values.

[Parameter]
[Category("Selecting")]
public IReadOnlyCollection<T>? SelectedValues { get; set; }

Property Value

IReadOnlyCollection<T>

Remarks

SelectedValuesChanged

Occurs when SelectedValues has changed.

[Parameter]
public EventCallback<IReadOnlyCollection<T>?> SelectedValuesChanged { get; set; }

Property Value

EventCallback<IReadOnlyCollection<T>>

SelectionMode

Controls how many items can be selected at one time.

[Parameter]
[Category("Selecting")]
public SelectionMode SelectionMode { get; set; }

Property Value

SelectionMode

Remarks

Defaults to SingleSelection.

ServerData

The function for asynchronously loading items.

[Parameter]
[Category("Data")]
public Func<T?, Task<IReadOnlyCollection<TreeItemData<T?>>>>? ServerData { get; set; }

Property Value

Func<T, Task<IReadOnlyCollection<TreeItemData<T>>>>

Remarks

When set, the function will be called to load the children of a parent item. When the parent node is null, top-level items should be returned.

Stylename

protected string Stylename { get; }

Property Value

string

TriState

Uses checkboxes which support an undetermined state.

[Parameter]
[Category("Selecting")]
public bool TriState { get; set; }

Property Value

bool

Remarks

Defaults to true. Only applies when SelectionMode is MultiSelection. When set, an item's checkbox will be in the "undetermined" state if child items have a mix of checked and unchecked states.

UncheckedIcon

The icon displayed for unchecked items.

[Parameter]
[Category("Selecting")]
public string UncheckedIcon { get; set; }

Property Value

string

Remarks

Defaults to CheckBoxOutlineBlank.

Width

Sets a fixed width.

[Parameter]
[Category("Appearance")]
public string? Width { get; set; }

Property Value

string

Remarks

Defaults to null. Can be a CSS value such as 500px or 30%.

Methods

BuildRenderTree(RenderTreeBuilder)

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

CollapseAllAsync()

Collapses all items and their children.

public Task CollapseAllAsync()

Returns

Task

ExpandAllAsync()

Expands all items and their children.

public Task ExpandAllAsync()

Returns

Task

FilterAsync()

Filters all items based on the FilterFunc function.

public Task FilterAsync()

Returns

Task

A task representing the asynchronous operation.

OnAfterRenderAsync(bool)

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Returns

Task

See Also