blazor-devexpress-dot-blazor-dot-dxtreeview-bdcb4022.md
Specifies the common template used to display all nodes.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
[Parameter]
public RenderFragment<ITreeViewNodeInfo> NodeTemplate { get; set; }
| Type | Description |
|---|---|
| RenderFragment<ITreeViewNodeInfo> |
The template content.
|
The NodeTemplate property allows you to specify the content of all TreeView nodes. Use the template’s context parameter to access an ITreeViewNodeInfo object that stores information about a node (text, level, bound data item, and so on).
The following example demonstrates how to:
change the text settings and the expand button’s position for the root node.
specify multi-line text content for other nodes.
<DxTreeView Data="@ComponentSets.Data"
@ref="@treeView">
<DataMappings>
<DxTreeViewDataMapping Children="ComponentSets" />
</DataMappings>
<NodeTemplate>
@{
var dataItem = (ComponentSet)context.DataItem;
}
@if (!context.IsLeaf) {
<h4 class="my-0 p-2 d-flex align-items-center">
@if (context.Expanded) {
<span class="oi oi-chevron-top"></span>
}
else {
<span class="oi oi-chevron-bottom"></span>
}
<span class="ms-3 flex-grow-1">@dataItem.Title</span>
</h4>
}
else {
<div class="d-flex p-2">
<div class="flex-grow-1">
<h5 class="mt-0">@dataItem.Title</h5>
@dataItem.Description
</div>
</div>
}
</NodeTemplate>
</DxTreeView>
@code {
DxTreeView treeView;
protected override Task OnAfterRenderAsync(bool firstRender) {
if(firstRender)
treeView.ExpandAll();
return base.OnAfterRenderAsync(firstRender);
}
}
public class ComponentSet {
Lazy<List<ComponentSet>> componentSets = new Lazy<List<ComponentSet>>();
public ComponentSet(string title, string imageUrl = "", string fluentImageUrl = "", string description = "", List<ComponentSet> componentSets = null) {
Title = title;
ImageUrl = imageUrl;
FluentImageUrl = fluentImageUrl;
Description = description;
if(componentSets != null)
ComponentSets.AddRange(componentSets);
}
public string ImageUrl { get; set; }
public string FluentImageUrl { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public List<ComponentSet> ComponentSets { get { return componentSets.Value; } }
}
public static class ComponentSets {
private static readonly List<ComponentSet> componentSets = new List<ComponentSet>() {
new ComponentSet("Components", componentSets:
new List<ComponentSet>() {
new ComponentSet("Data Grid",
"The DevExpress Data Grid for Blazor allows you to display and manage data in a tabular format."),
new ComponentSet("Pivot Grid",
"The DevExpress Pivot Grid for Blazor allows you to display and analyze multi-dimensional data from an underlying data source."),
new ComponentSet("Charts",
"DevExpress Charts for Blazor help you transform data to its most appropriate, concise, and readable visual representation."),
new ComponentSet("Scheduler",
"The DevExpress Scheduler for Blazor allows you to create, display, and edit scheduled appointments in a calendar format."),
new ComponentSet("Data Editors",
"DevExpress Data Editors for Blazor include components that can be used as standalone editors or within the Data Grid edit form."),
}
)
};
public static List<ComponentSet> Data { get { return componentSets; } }
}
The NodeTextTemplate property allows you to define a template for the text displayed in the TreeView node labels.
In unbound mode, you can also use the DxTreeViewNode.TextTemplate and DxTreeViewNode.Template properties to apply templates to individual nodes.
Run Demo: TreeView - Templates
See Also