TreeViewPanel

April 9, 2026 · View on GitHub

A panel that hosts a searchable, collapsible tree of TreeViewSection items. Provides a filter text box, collapse-all/expand-all buttons, and raises a unified SelectionChanged event when any section's selection changes.

Basic usage

<TreeViewPanel>
    <TreeViewSection Header="Section 1">
        <TreeViewItem Content="Item 1.1" />
        <TreeViewItem Content="Item 1.2" />
    </TreeViewSection>
    <TreeViewSection Header="Section 2">
        <TreeViewItem Content="Item 2.1" />
        <TreeViewItem Content="Item 2.2" />
    </TreeViewSection>
</TreeViewPanel>

Properties

PropertyTypeDefaultDescription
FilterTextstring?Text used to filter items across all sections
FilterWatermarkstring"Filter..."Watermark shown in the filter text box
SelectedItemobject?Currently selected item (across all sections)
SelectedSectionTreeViewSection?Section that owns the currently selected item
ShowExpandButtonbooltrueWhether the expand-all button is visible
ShowCollapseButtonbooltrueWhether the collapse-all button is visible
ExpandButtonColumnWidthGridLength32Width of the expand button column
CollapseButtonColumnWidthGridLength32Width of the collapse button column
SectionsAvaloniaList<TreeViewSection>Collection of sections displayed in the panel

Events

EventDescription
SelectionChangedRaised when the selected item changes in any section
FilterChangedRaised when the filter text changes

Methods

MethodDescription
ExpandAll()Expands all sections
CollapseAll()Collapses all sections
ClearFilter()Clears the filter text

Filtering

The filter text box automatically filters items across all sections. When text is entered, only items matching the filter (case-insensitive) are displayed:

<TreeViewPanel FilterWatermark="Search items..." />
// Set filter programmatically
treeViewPanel.FilterText = "search term";

Expand/collapse buttons

The expand-all and collapse-all buttons allow users to quickly expand or collapse all sections at once.

treeViewPanel.ExpandAll();
treeViewPanel.CollapseAll();

Control button visibility:

<TreeViewPanel ShowExpandButton="True"
              ShowCollapseButton="True" />
treeViewPanel.ShowExpandButton = false;
treeViewPanel.ShowCollapseButton = false;

Button column widths

Customize the width of the expand and collapse button columns:

<TreeViewPanel ExpandButtonColumnWidth="40"
              CollapseButtonColumnWidth="40" />
treeViewPanel.ExpandButtonColumnWidth = new GridLength(40);
treeViewPanel.CollapseButtonColumnWidth = new GridLength(40);

These columns animate when the search box gains/loses focus.

Selection handling

When an item is selected in any section, the SelectionChanged event is raised. The SelectedItem and SelectedSection properties are updated automatically:

treeViewPanel.SelectionChanged += (sender, e) =>
{
    var selectedItem = treeViewPanel.SelectedItem;
    var selectedSection = treeViewPanel.SelectedSection;
};

Filter changed event

Handle filter text changes:

treeViewPanel.FilterChanged += (sender, text) =>
{
    // Respond to filter text changes
};