HypernovaDesktop Components · docs
Binarymission
WPF › Tree List View › BinaryTreeListView

BinaryTreeListView

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Controls.TreeControls

A tree and a grid in one control: rows that nest, expand and collapse like a TreeView, laid out in resizable, sortable, reorderable columns like a ListView in grid view.

public partial class BinaryTreeListView : TreeView

Inherits from / implements: TreeView

Remarks

Use it wherever data has both a hierarchy and several facts per row: a project plan with owners and dates, a file system with sizes and types, a chart of accounts with balances, an organisation with roles and locations.

Columns

Add a GridViewColumn to Columns for each column, exactly as for a GridView: give it a GridViewColumn.DisplayMemberBinding for plain text, or a GridViewColumn.CellTemplate for anything richer. One column carries the tree – the indent, the expander and the connecting lines. It is the first column unless you choose another with TreeListViewColumnIndex or TreeListViewColumn. The rows line up across every level of the tree, and follow the headings when the user resizes or drags them.

Rows

There are two ways to give the control its rows, and every feature works with both.

Sorting

With AllowsColumnSorting on, a click on a heading sorts by that column and a second click reverses it; SortByColumn and ClearColumnSort do the same from code. Each branch is sorted within itself, so children stay under their parents. A column that draws its cells with a template has no binding to sort by – name the property with SetSortMemberPath.

Selection

Single selection works as in any tree view, through TreeView.SelectedItem and TreeView.SelectedItemChanged. Turn on IsMultiSelectionEnabled to let Ctrl+click add and remove rows, and IsShiftMultiSelectionEnabled as well to let Shift+click select every row on show between the last row clicked and this one, at any depth. The rows selected that way are in MultiSelectedItems.

Appearance

Theme applies one of eight built-in colour schemes in a single setting, and any brush can then be set on its own to depart from it. Alternate-row striping (AlternateRowBackgroundBrush) counts the rows as they are drawn, so it stays correct as branches open, close and sort. The expander can be drawn in five shapes (ExpanderGlyph), the connecting lines solid or dotted, and the column headings in colours of your own. The default colour given for each brush is the one used with no Binarymission skin in force; a skin (Binarymission.WPF.Skinning) supplies its own.

Examples

A bound tree of folders and files in XAML. Each FolderRow has Name, Kind, Size and Modified properties and a Children collection; the window's data context exposes the top-level rows as Roots.

<Window x:Class="Explorer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tlv="clr-namespace:Binarymission.WPF.Controls.TreeControls;assembly=Binarymission.WPF.Controls.BinaryTreeListView"
        Title="Explorer" Width="900" Height="560">

    <tlv:BinaryTreeListView ItemsSource="{Binding Roots}"
                            TreeListViewColumnIndex="0"
                            AllowsColumnSorting="True"
                            AllowsColumnReorder="True"
                            IsMultiSelectionEnabled="True"
                            IsShiftMultiSelectionEnabled="True"
                            ExpanderGlyph="Chevron"
                            Theme="Office">

        <tlv:BinaryTreeListView.ItemTemplate>
            <HierarchicalDataTemplate ItemsSource="{Binding Children}" />
        </tlv:BinaryTreeListView.ItemTemplate>

        <tlv:BinaryTreeListView.Columns>
            <GridViewColumn Header="Name"     Width="320" DisplayMemberBinding="{Binding Name}" />
            <GridViewColumn Header="Type"     Width="140" DisplayMemberBinding="{Binding Kind}" />
            <GridViewColumn Header="Size"     Width="100" DisplayMemberBinding="{Binding Size, StringFormat={}{0:N0} KB}" />
            <GridViewColumn Header="Modified" Width="160" DisplayMemberBinding="{Binding Modified, StringFormat=d}" />
        </tlv:BinaryTreeListView.Columns>
    </tlv:BinaryTreeListView>
</Window>

The same control built in code, with the rows added as nodes rather than bound. The row objects can be any class with public properties.

using System.Windows.Controls;
using System.Windows.Data;
using Binarymission.WPF.Controls.TreeControls;

public sealed class TaskRow
{
    public string Name { get; set; }
    public string Owner { get; set; }
    public int Percent { get; set; }
}

BinaryTreeListView plan = new BinaryTreeListView
{
    AllowsColumnSorting = true,
    IsMultiSelectionEnabled = true,
    Theme = BinaryTreeListViewTheme.Office
};

plan.Columns.Add(new GridViewColumn { Header = "Task",  Width = 280, DisplayMemberBinding = new Binding("Name") });
plan.Columns.Add(new GridViewColumn { Header = "Owner", Width = 140, DisplayMemberBinding = new Binding("Owner") });
plan.Columns.Add(new GridViewColumn { Header = "Done",  Width = 80,  DisplayMemberBinding = new Binding("Percent") { StringFormat = "{0}%" } });
plan.TreeListViewColumnIndex = 0;

BinaryTreeListViewItem design = new BinaryTreeListViewItem
{
    Header = new TaskRow { Name = "Design", Owner = "Priya", Percent = 60 },
    IsExpanded = true
};
design.Items.Add(new BinaryTreeListViewItem { Header = new TaskRow { Name = "Wireframes", Owner = "Priya", Percent = 100 } });
design.Items.Add(new BinaryTreeListViewItem { Header = new TaskRow { Name = "Visual design", Owner = "Tom", Percent = 20 } });

plan.Items.Add(design);

See also

Members at a glance

Constructors
BinaryTreeListViewCreates a tree list view with no columns and no rows.
Properties
AllowsColumnReorderGets or sets whether the user can move a column by dragging its heading.
AllowsColumnSortingGets or sets whether clicking a column heading sorts the rows by that column.
AlternateRowBackgroundBrushGets or sets the background of every other row – the second, fourth, sixth and so on – counting the rows as they are drawn on screen.
CollapseButtonImageGets or sets a picture to draw as the expander of an expanded row, in place of the shape the control draws.
ColumnHeaderBackgroundBrushGets or sets the fill behind the column headings.
ColumnHeaderBorderBrushGets or sets the colour of the edge drawn to the right of and under each column heading.
ColumnHeaderForegroundBrushGets or sets the colour of the column headings' text.
ColumnHeaderHeightGets or sets the height of the column heading row.
ColumnHeaderHoverBackgroundBrushGets or sets the fill behind a column heading while the pointer is over it.
ColumnHeaderPressedBackgroundBrushGets or sets the fill behind a column heading while it is being pressed.
ColumnReorderIndicatorBrushGets or sets the colour of the line that shows where a dragged column will land, and of the wash over the column being dragged.
ColumnsGets the columns the rows are laid out in.
ExpandButtonImageGets or sets a picture to draw as the expander of a collapsed row, in place of the shape the control draws.
ExpandCollapseBorderBrushGets or sets the colour of the box drawn around the expander's mark.
ExpandCollapseButtonImageStretchGets or sets how ExpandButtonImage and CollapseButtonImage are sized in the expander.
ExpandCollapseControlFillBrushGets or sets the colour inside the box of the boxed expander shapes, BinaryTreeListViewExpanderGlyph.PlusMinus and BinaryTreeListViewExpanderGlyph.BoxedChevron.
ExpandCollapsePlusMinusBrushGets or sets the colour of the expander's mark: the plus and minus, the chevron, the triangle, or the whole of the BinaryTreeListViewExpanderGlyph.Disc.
ExpanderGlyphGets or sets the shape the expander is drawn as.
InactiveSelectionBackgroundBrushGets or sets the background of a selected row while the control does not have focus.
InactiveSelectionForegroundBrushGets or sets the text colour of a selected row while the control does not have focus.
IsMultiSelectionEnabledGets or sets whether the user can hold several rows selected at once.
IsNodesConnectingLineDottedGets or sets whether the lines that join the rows are drawn dotted rather than solid.
IsNodesConnectingLineVisibleGets or sets whether lines are drawn joining each row to its parent and its siblings.
IsShiftMultiSelectionEnabledGets or sets whether Shift+click selects a range of rows.
MouseOverBackgroundBrushGets or sets the row background drawn while the pointer is over it.
MouseOverForegroundBrushGets or sets the row foreground drawn while the pointer is over it.
MultiSelectedItemsGets the rows the user has selected while multi-selection is on.
NodesConnectingLineBrushGets or sets the colour of the lines that join the rows of the tree.
RenderCollapseExpandVisualAlwaysInTheFirstColumnGets or sets whether the tree is always drawn in the left-most column, whichever column TreeListViewColumn names.
RowBackgroundBrushGets or sets the background of the first, third, fifth row and so on, counting the rows as they are drawn on screen.
RowSeparatorBrushGets or sets the colour of a thin line drawn under every row.
SelectionBackgroundBrushGets or sets the background of a selected row while the control has focus.
SelectionForegroundBrushGets or sets the text colour of a selected row while the control has focus.
SortDirectionGets the direction SortedColumn is sorted in.
SortGlyphBrushGets or sets the colour of the arrow drawn over the heading of the column the rows are sorted by.
SortedColumnGets the column the rows are sorted by.
ThemeGets or sets the built-in colour scheme the control is drawn in.
TreeListViewColumnGets or sets the column that carries the tree: the indent, the expander and the connecting lines.
TreeListViewColumnIndexGets or sets the position in Columns of the column that carries the tree.
TreeListViewItemIsRenderedWithRoundedCornerGets or sets whether each row's background – its selection, hover and stripe colour – is drawn with rounded corners.
Methods
ClearColumnSortStops sorting by a column and removes the sort arrow.
CollapseAllNodesCollapses every row in the tree, at every level, and scrolls back to the first row.
ExpandAllNodesExpands every row in the tree, at every level.
ExpandNodeByIndexExpands one top-level row and every row beneath it.
ExpandNodesByIndicesExpands several top-level rows, each with every row beneath it, then scrolls the first top-level row into view.
GetContainerForItemOverrideCreates the row that shows one bound item: a BinaryTreeListViewItem.
GetSortMemberPathGets the name of the property a column is sorted by.
IsItemItsOwnContainerOverrideTells the control whether an item is already a row, and so needs no row of its own.
OnApplyTemplateApplies the control's template.
OnItemsChangedLays the alternate-row stripes again when top-level rows are added, removed or moved.
RefreshRowDecorationsDraws the connecting lines and row separators of every row on screen again.
RefreshRowStripingLays the alternating row backgrounds again, in the order the rows are drawn.
SelectNodeByIndexSelects a top-level row by its position.
SelectNodesByIndicesSelects several top-level rows by their positions, then scrolls the first top-level row into view.
SetSortMemberPathSets the name of the property a column is sorted by.
SortByColumnSorts every branch of the tree by one column.
Events
ColumnReorderedOccurs after a column has moved: dragged to a new place by the user, or moved in code with Move on Columns.
ColumnSortedOccurs after the rows have been sorted by a column, by a click on its heading or by SortByColumn.
Fields
AllowsColumnReorderPropertyIdentifies the AllowsColumnReorder dependency property.
AllowsColumnSortingPropertyIdentifies the AllowsColumnSorting dependency property.
AlternateRowBackgroundBrushPropertyIdentifies the AlternateRowBackgroundBrush dependency property.
CollapseButtonImagePropertyIdentifies the CollapseButtonImage dependency property.
ColumnHeaderBackgroundBrushPropertyIdentifies the ColumnHeaderBackgroundBrush dependency property.
ColumnHeaderBorderBrushPropertyIdentifies the ColumnHeaderBorderBrush dependency property.
ColumnHeaderForegroundBrushPropertyIdentifies the ColumnHeaderForegroundBrush dependency property.
ColumnHeaderHeightPropertyIdentifies the ColumnHeaderHeight dependency property.
ColumnHeaderHoverBackgroundBrushPropertyIdentifies the ColumnHeaderHoverBackgroundBrush dependency property.
ColumnHeaderPressedBackgroundBrushPropertyIdentifies the ColumnHeaderPressedBackgroundBrush dependency property.
ColumnReorderIndicatorBrushPropertyIdentifies the ColumnReorderIndicatorBrush dependency property.
ExpandButtonImagePropertyIdentifies the ExpandButtonImage dependency property.
ExpandCollapseBorderBrushPropertyIdentifies the ExpandCollapseBorderBrush dependency property.
ExpandCollapseButtonImageStretchPropertyIdentifies the ExpandCollapseButtonImageStretch dependency property.
ExpandCollapseControlFillBrushPropertyIdentifies the ExpandCollapseControlFillBrush dependency property.
ExpandCollapsePlusMinusBrushPropertyIdentifies the ExpandCollapsePlusMinusBrush dependency property.
ExpanderGlyphPropertyIdentifies the ExpanderGlyph dependency property.
InactiveSelectionBackgroundBrushPropertyIdentifies the InactiveSelectionBackgroundBrush dependency property.
InactiveSelectionForegroundBrushPropertyIdentifies the InactiveSelectionForegroundBrush dependency property.
IsMultiSelectionEnabledPropertyIdentifies the IsMultiSelectionEnabled dependency property.
IsNodesConnectingLineDottedPropertyIdentifies the IsNodesConnectingLineDotted dependency property.
IsNodesConnectingLineVisiblePropertyIdentifies the IsNodesConnectingLineVisible dependency property.
IsShiftMultiSelectionEnabledPropertyIdentifies the IsShiftMultiSelectionEnabled dependency property.
MouseOverBackgroundBrushPropertyIdentifies the MouseOverBackgroundBrush dependency property.
MouseOverForegroundBrushPropertyIdentifies the MouseOverForegroundBrush dependency property.
NodesConnectingLineBrushPropertyIdentifies the NodesConnectingLineBrush dependency property.
RenderCollapseExpandVisualAlwaysInTheFirstColumnPropertyIdentifies the RenderCollapseExpandVisualAlwaysInTheFirstColumn dependency property.
RowBackgroundBrushPropertyIdentifies the RowBackgroundBrush dependency property.
RowSeparatorBrushPropertyIdentifies the RowSeparatorBrush dependency property.
SelectionBackgroundBrushPropertyIdentifies the SelectionBackgroundBrush dependency property.
SelectionForegroundBrushPropertyIdentifies the SelectionForegroundBrush dependency property.
SortDirectionPropertyIdentifies the SortDirection dependency property.
SortGlyphBrushPropertyIdentifies the SortGlyphBrush dependency property.
SortMemberPathPropertyIdentifies the SortMemberPath attached property: the name of the property a column is sorted by, for a column that draws its cells with a template and so has no GridViewColumn.DisplayMemberBinding to read one from.
SortedColumnPropertyIdentifies the SortedColumn dependency property.
ThemePropertyIdentifies the Theme dependency property.
TreeListViewColumnIndexPropertyIdentifies the TreeListViewColumnIndex dependency property.
TreeListViewColumnPropertyIdentifies the TreeListViewColumn dependency property.
TreeListViewItemIsRenderedWithRoundedCornerPropertyIdentifies the TreeListViewItemIsRenderedWithRoundedCorner dependency property.

Constructors

BinaryTreeListView

public BinaryTreeListView()

Creates a tree list view with no columns and no rows.

Remarks

Add columns to Columns, then give the control its rows through ItemsControl.ItemsSource or ItemsControl.Items.

Properties

AllowsColumnReorder

public bool AllowsColumnReorder

Gets or sets whether the user can move a column by dragging its heading.

Value
true to allow it; the default.
Remarks

While a heading is dragged, the column is washed in ColumnReorderIndicatorBrush and a line shows where it will land. The tree column can be moved like any other; the tree goes with it. ColumnReordered is raised after each move.

AllowsColumnSorting

public bool AllowsColumnSorting

Gets or sets whether clicking a column heading sorts the rows by that column.

Value
true to sort on click. The default is false.
Remarks

The first click on a heading sorts ascending and the next click descending; an arrow over the heading shows which, in SortGlyphBrush. Every branch is sorted within itself, so the tree keeps its shape: top-level rows are ordered against each other, each row's children against each other, and so on down.

A column is sorted by the property its GridViewColumn.DisplayMemberBinding reads. A column that draws its cells with a template names its property with SetSortMemberPath; without one, clicking its heading does nothing.

Numbers sort by value, dates by date, other comparable values by their own order, and anything else by its text, ignoring case. Empty values sort first in ascending order.

Turning this off removes the sort arrow and, for a bound tree, the ordering.

Example
<tlv:BinaryTreeListView AllowsColumnSorting="True">
    <tlv:BinaryTreeListView.Columns>
        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" />
        <!-- A templated column says what to sort by. -->
        <GridViewColumn Header="Status" tlv:BinaryTreeListView.SortMemberPath="Status">
            <GridViewColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Status}" FontWeight="SemiBold" />
                </DataTemplate>
            </GridViewColumn.CellTemplate>
        </GridViewColumn>
    </tlv:BinaryTreeListView.Columns>
</tlv:BinaryTreeListView>
See also

AlternateRowBackgroundBrush

public Brush AlternateRowBackgroundBrush

Gets or sets the background of every other row – the second, fourth, sixth and so on – counting the rows as they are drawn on screen.

Value
The default is null: no striping.
Remarks

The control counts the rows on show, from the top, passing over collapsed branches, and lays the stripes again whenever a branch opens or closes, the rows are sorted or the items change. So the stripes always alternate on screen, however deep the tree. If rows are expanded by something the control does not see – a binding to TreeViewItem.IsExpanded, say – call RefreshRowStriping afterwards.

Example
<tlv:BinaryTreeListView RowBackgroundBrush="White"
                        AlternateRowBackgroundBrush="#F4F7FB"
                        RowSeparatorBrush="#E3E8EF" />
See also

CollapseButtonImage

public ImageSource CollapseButtonImage

Gets or sets a picture to draw as the expander of an expanded row, in place of the shape the control draws.

Value
The image, or null – the default – to draw the shape chosen by ExpanderGlyph.
Remarks

See ExpandButtonImage, which works the same way for collapsed rows.

ColumnHeaderBackgroundBrush

public Brush ColumnHeaderBackgroundBrush

Gets or sets the fill behind the column headings.

Value
The default is a near-white (#FCFDFF); each Theme sets its own.

ColumnHeaderBorderBrush

public Brush ColumnHeaderBorderBrush

Gets or sets the colour of the edge drawn to the right of and under each column heading.

Value
The default is a light grey-blue (#CED7E4).

ColumnHeaderForegroundBrush

public Brush ColumnHeaderForegroundBrush

Gets or sets the colour of the column headings' text.

Value
The default is a dark slate (#242F3E).

ColumnHeaderHeight

public double ColumnHeaderHeight

Gets or sets the height of the column heading row.

Value
The height in device-independent units (1/96 inch). The default is 28.

ColumnHeaderHoverBackgroundBrush

public Brush ColumnHeaderHoverBackgroundBrush

Gets or sets the fill behind a column heading while the pointer is over it.

Value
The default is a pale blue (#E9F2FE).

ColumnHeaderPressedBackgroundBrush

public Brush ColumnHeaderPressedBackgroundBrush

Gets or sets the fill behind a column heading while it is being pressed.

Value
The default is a light blue (#C6DBF7).

ColumnReorderIndicatorBrush

public Brush ColumnReorderIndicatorBrush

Gets or sets the colour of the line that shows where a dragged column will land, and of the wash over the column being dragged.

Value
The default is a mid blue (#1F77D0).

Columns

public GridViewColumnCollection Columns

Gets the columns the rows are laid out in.

Value
The control's column collection, never null. Add a GridViewColumn for each column, with a GridViewColumn.DisplayMemberBinding or a GridViewColumn.CellTemplate, a GridViewColumn.Header and, if you like, a GridViewColumn.Width.
Remarks

Columns can be added, removed and reordered at any time; every row follows. In XAML, add them inside a BinaryTreeListView.Columns property element.

Example
<tlv:BinaryTreeListView.Columns>
    <GridViewColumn Header="Account" Width="280" DisplayMemberBinding="{Binding Name}" />
    <GridViewColumn Header="Balance" Width="120">
        <GridViewColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Balance, StringFormat=C}" TextAlignment="Right" />
            </DataTemplate>
        </GridViewColumn.CellTemplate>
    </GridViewColumn>
</tlv:BinaryTreeListView.Columns>

ExpandButtonImage

public ImageSource ExpandButtonImage

Gets or sets a picture to draw as the expander of a collapsed row, in place of the shape the control draws.

Value
The image, or null – the default – to draw the shape chosen by ExpanderGlyph.
Remarks

While this or CollapseButtonImage is set, the image is drawn over the ExpanderGlyph shape, so set both. ExpandCollapseButtonImageStretch sizes them. The drawn shapes need no images: they are sharp at every display scale and take their colours from ExpandCollapseControlFillBrush, ExpandCollapseBorderBrush and ExpandCollapsePlusMinusBrush.

Example
<!-- Your own expander pictures, from the application's resources. -->
<tlv:BinaryTreeListView ExpandButtonImage="/Images/folder-closed.png"
                        CollapseButtonImage="/Images/folder-open.png"
                        ExpandCollapseButtonImageStretch="Uniform" />

ExpandCollapseBorderBrush

public Brush ExpandCollapseBorderBrush

Gets or sets the colour of the box drawn around the expander's mark.

Value
The default is the system's grey-text colour. Only the boxed shapes, BinaryTreeListViewExpanderGlyph.PlusMinus and BinaryTreeListViewExpanderGlyph.BoxedChevron, draw a box.
See also

ExpandCollapseButtonImageStretch

public Stretch ExpandCollapseButtonImageStretch

Gets or sets how ExpandButtonImage and CollapseButtonImage are sized in the expander.

Value
The default is Stretch.None: each image is drawn at its own size.

ExpandCollapseControlFillBrush

public Brush ExpandCollapseControlFillBrush

Gets or sets the colour inside the box of the boxed expander shapes, BinaryTreeListViewExpanderGlyph.PlusMinus and BinaryTreeListViewExpanderGlyph.BoxedChevron.

Value
The default is the system's window colour.
See also

ExpandCollapsePlusMinusBrush

public Brush ExpandCollapsePlusMinusBrush

Gets or sets the colour of the expander's mark: the plus and minus, the chevron, the triangle, or the whole of the BinaryTreeListViewExpanderGlyph.Disc.

Value
The default is the system's window-text colour; each Theme uses its accent colour.
See also

ExpanderGlyph

public BinaryTreeListViewExpanderGlyph ExpanderGlyph

Gets or sets the shape the expander is drawn as.

Value
One of the five BinaryTreeListViewExpanderGlyph shapes. The default is BinaryTreeListViewExpanderGlyph.PlusMinus.
Remarks

The shape is drawn by the control, sharp at every display scale, and lightens under the pointer. Its colours are ExpandCollapsePlusMinusBrush for the mark, and ExpandCollapseControlFillBrush and ExpandCollapseBorderBrush for the box of the boxed shapes. Each Theme sets all three.

To use pictures of your own instead, set ExpandButtonImage and CollapseButtonImage; they are drawn over the shape.

Example
<tlv:BinaryTreeListView ExpanderGlyph="BoxedChevron"
                        ExpandCollapsePlusMinusBrush="SteelBlue" />

InactiveSelectionBackgroundBrush

public Brush InactiveSelectionBackgroundBrush

Gets or sets the background of a selected row while the control does not have focus.

Value
The inactive selection brush. Defaults to the system's control colour.
Remarks

SelectionBackgroundBrush applies only while the tree has focus; set this as well to keep a designed selection colour when the user clicks elsewhere.

InactiveSelectionForegroundBrush

public Brush InactiveSelectionForegroundBrush

Gets or sets the text colour of a selected row while the control does not have focus.

Value
The inactive selection text brush. Defaults to the system's control text colour.

IsMultiSelectionEnabled

public bool IsMultiSelectionEnabled

Gets or sets whether the user can hold several rows selected at once.

Value
true to let Ctrl+click select and deselect rows while keeping the others. The default is false.
Remarks

Each Ctrl+click toggles one row in or out of the selection, keeping the row last clicked without Ctrl, and a plain click starts again with a single row. Turn on IsShiftMultiSelectionEnabled as well for Shift+click range selection.

The rows chosen with Ctrl+click and Shift+click are listed in MultiSelectedItems.

Example
tree.IsMultiSelectionEnabled = true;

archiveButton.Click += (sender, e) =>
{
    foreach (BinaryTreeListViewItem row in tree.MultiSelectedItems)
    {
        // Header is the row object in a built tree; DataContext is, in a bound one.
        Archive(row.Header);
    }
};
See also

IsNodesConnectingLineDotted

public bool IsNodesConnectingLineDotted

Gets or sets whether the lines that join the rows are drawn dotted rather than solid.

Value
true for dotted lines, as in the classic Windows tree view. The default is false.
See also

IsNodesConnectingLineVisible

public bool IsNodesConnectingLineVisible

Gets or sets whether lines are drawn joining each row to its parent and its siblings.

Value
true to draw the lines; the default. They are drawn in the tree column only, in NodesConnectingLineBrush.
See also

IsShiftMultiSelectionEnabled

public bool IsShiftMultiSelectionEnabled

Gets or sets whether Shift+click selects a range of rows.

Value
true to allow range selection. The default is false. It takes effect only while IsMultiSelectionEnabled is also on.
Remarks

The range runs from the row last clicked without Shift (or last added with Ctrl) to the row clicked, in either direction, over the rows on show in the order they are drawn – so it can cross parents and levels, as in Windows Explorer. Rows inside collapsed branches are not included. The rows selected are in MultiSelectedItems.

Example
<tlv:BinaryTreeListView IsMultiSelectionEnabled="True"
                        IsShiftMultiSelectionEnabled="True" />

MouseOverBackgroundBrush

public Brush MouseOverBackgroundBrush

Gets or sets the row background drawn while the pointer is over it.

Value
The hover brush. Null by default, which draws no hover at all.
Remarks

Set a brush to give rows a hover state; with the default of null rows look the same whether or not the pointer is over them.

MouseOverForegroundBrush

public Brush MouseOverForegroundBrush

Gets or sets the row foreground drawn while the pointer is over it.

Value
The hover text brush. Null by default, leaving the text as it is.

MultiSelectedItems

public List<BinaryTreeListViewItem> MultiSelectedItems

Gets the rows the user has selected while multi-selection is on.

Value
The selected rows. Each entry is the row's BinaryTreeListViewItem; its Header (or its DataContext when the tree is bound) is the row object. A plain click leaves just the row clicked; Ctrl+click adds or removes rows, and Shift+click sets a range.
Remarks

The list is the control's own. Read it, but change the selection through the rows' TreeViewItem.IsSelected, or SelectNodesByIndices, rather than by adding or removing entries.

See also

NodesConnectingLineBrush

public SolidColorBrush NodesConnectingLineBrush

Gets or sets the colour of the lines that join the rows of the tree.

Value
A solid colour brush. The default is black; each Theme sets its own.
See also

RenderCollapseExpandVisualAlwaysInTheFirstColumn

public bool RenderCollapseExpandVisualAlwaysInTheFirstColumn

Gets or sets whether the tree is always drawn in the left-most column, whichever column TreeListViewColumn names.

Value
true to keep the tree in the first column on screen, even after the user drags another column in front of it. The default is false: the tree stays in its column wherever that column is moved.

RowBackgroundBrush

public Brush RowBackgroundBrush

Gets or sets the background of the first, third, fifth row and so on, counting the rows as they are drawn on screen.

Value
The default is null, leaving those rows the control's own background.
Remarks

Rows are striped only while AlternateRowBackgroundBrush is set; this brush is the other half of the pair.

See also

RowSeparatorBrush

public Brush RowSeparatorBrush

Gets or sets the colour of a thin line drawn under every row.

Value
The default is null: no line. Each Theme sets one.
Remarks

A separator makes wide rows easier to follow across the columns, much as gridlines do in a spreadsheet; alternate-row striping (AlternateRowBackgroundBrush) does the same job more softly.

SelectionBackgroundBrush

public Brush SelectionBackgroundBrush

Gets or sets the background of a selected row while the control has focus.

Value
When it is not set, the control's style supplies one – the colour of the skin in force, when a Binarymission skin is applied. Each Theme sets its own.
See also

SelectionForegroundBrush

public Brush SelectionForegroundBrush

Gets or sets the text colour of a selected row while the control has focus.

Value
The default is the system's highlighted-text colour.
See also

SortDirection

public ListSortDirection SortDirection

Gets the direction SortedColumn is sorted in.

Value
ListSortDirection.Ascending or ListSortDirection.Descending. Meaningful only while SortedColumn is set.

SortGlyphBrush

public Brush SortGlyphBrush

Gets or sets the colour of the arrow drawn over the heading of the column the rows are sorted by.

Value
The default is a mid blue (#3B63A0); each Theme sets its own.

SortedColumn

public GridViewColumn SortedColumn

Gets the column the rows are sorted by.

Value
The column, or null when the rows are in the order they were added or bound.
See also

Theme

public BinaryTreeListViewTheme Theme

Gets or sets the built-in colour scheme the control is drawn in.

Value
One of the BinaryTreeListViewTheme schemes. The default is BinaryTreeListViewTheme.Custom: no scheme, the control's own default colours.
Remarks

A scheme sets every colour the control has – the background, text and border, the row stripes and separators, the connecting lines and expander, hover and selection, the sort arrow, and the column headings – in one setting.

The scheme writes the control's brush properties, so set any one of them afterwards to change that colour alone. Setting the theme back to BinaryTreeListViewTheme.Custom clears every brush a scheme writes, returning the control to its default colours – or to the skin's, when a Binarymission skin is in force.

Example
<!-- The dark scheme, with the selection in the application's own accent colour. -->
<tlv:BinaryTreeListView Theme="Midnight"
                        SelectionBackgroundBrush="#3A6FD8" />
// Follow the application's light and dark modes.
tree.Theme = darkMode ? BinaryTreeListViewTheme.Midnight : BinaryTreeListViewTheme.Office;

TreeListViewColumn

public GridViewColumn TreeListViewColumn

Gets or sets the column that carries the tree: the indent, the expander and the connecting lines.

Value
One of the columns in Columns. When it is null – the default – or not one of the control's columns, the first column carries the tree.
Remarks

Every other column draws a plain cell. The rows keep their parents and children whichever column carries the tree, and it can be changed at any time.

TreeListViewColumnIndex always reports this column's position, including after the user drags it somewhere else. Setting either property sets the other. RenderCollapseExpandVisualAlwaysInTheFirstColumn overrides both.

Example
GridViewColumn nameColumn = new GridViewColumn { Header = "Name", DisplayMemberBinding = new Binding("Name") };
tree.Columns.Add(new GridViewColumn { Header = "Id", DisplayMemberBinding = new Binding("Id") });
tree.Columns.Add(nameColumn);

// The tree is drawn in the Name column, wherever the user moves it.
tree.TreeListViewColumn = nameColumn;

TreeListViewColumnIndex

public int TreeListViewColumnIndex

Gets or sets the position in Columns of the column that carries the tree.

Value
A zero-based column position, or -1 (the default) when no column has been chosen, in which case the first column carries the tree.
Remarks

It can be set before any columns are added, in XAML or in code: the column at that position becomes the tree column as soon as there is one. After that it follows TreeListViewColumn, so it changes when the user drags the tree column to a new place.

TreeListViewItemIsRenderedWithRoundedCorner

public bool TreeListViewItemIsRenderedWithRoundedCorner

Gets or sets whether each row's background – its selection, hover and stripe colour – is drawn with rounded corners.

Value
true for corners rounded by four pixels; the default. false for square ones.

Methods

ClearColumnSort

public void ClearColumnSort()

Stops sorting by a column and removes the sort arrow.

Remarks

A bound tree goes back to the order of its source. A built tree's nodes stay where the last sort put them, because they were moved rather than viewed in order.

See also

CollapseAllNodes

public void CollapseAllNodes()

Collapses every row in the tree, at every level, and scrolls back to the first row.

See also

ExpandAllNodes

public void ExpandAllNodes(bool shouldScrollBackToTop)

Expands every row in the tree, at every level.

Parameters
shouldScrollBackToTop
true to scroll the first top-level row back into view afterwards; false to leave the scroll position where expanding left it.
Example
expandAllButton.Click += (sender, e) => tree.ExpandAllNodes(true);
collapseAllButton.Click += (sender, e) => tree.CollapseAllNodes();
See also

ExpandNodeByIndex

public void ExpandNodeByIndex(int index)

Expands one top-level row and every row beneath it.

Parameters
index
The zero-based position of the row among the top-level rows. A position that is negative or past the last row is ignored.
See also

ExpandNodesByIndices

public void ExpandNodesByIndices(IEnumerable<int> indices)

Expands several top-level rows, each with every row beneath it, then scrolls the first top-level row into view.

Parameters
indices
The zero-based positions of the rows among the top-level rows. Positions out of range are ignored; null or an empty sequence does nothing.
See also

GetContainerForItemOverride

protected override DependencyObject GetContainerForItemOverride()

Creates the row that shows one bound item: a BinaryTreeListViewItem.

Returns

GetSortMemberPath static

public static string GetSortMemberPath(DependencyObject column)

Gets the name of the property a column is sorted by.

Parameters
column
The column, usually a GridViewColumn.
Returns

The property's name, or null when none has been set (the column's GridViewColumn.DisplayMemberBinding is used instead).

IsItemItsOwnContainerOverride

protected override bool IsItemItsOwnContainerOverride(object item)

Tells the control whether an item is already a row, and so needs no row of its own.

Parameters
item
An entry in ItemsControl.Items.
Returns

true when item is a BinaryTreeListViewItem.

OnApplyTemplate

public override void OnApplyTemplate()

Applies the control's template.

Remarks

The heading row and the sort arrow belong to the template that has just been thrown away, so both are looked for again the next time they are wanted.

OnItemsChanged

protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)

Lays the alternate-row stripes again when top-level rows are added, removed or moved.

Parameters
e
What changed in the collection.
Remarks

A derived class that overrides this should call the base implementation.

RefreshRowDecorations

public void RefreshRowDecorations()

Draws the connecting lines and row separators of every row on screen again.

Remarks

The control redraws them when its own properties change. Call this after changing something the rows are drawn from that the control does not watch, such as a brush you have modified in place rather than replaced.

RefreshRowStriping

public void RefreshRowStriping()

Lays the alternating row backgrounds again, in the order the rows are drawn.

Remarks

The control calls this itself whenever a branch opens or closes, the rows are sorted or the items change. Call it when rows are expanded or collapsed by something else – a binding to TreeViewItem.IsExpanded, for example – which the control has no way to notice.

See also

SelectNodeByIndex

public void SelectNodeByIndex(int index)

Selects a top-level row by its position.

Parameters
index
The zero-based position of the row among the top-level rows. A position that is negative or past the last row is ignored.
Remarks

Only top-level rows are reached this way. To select a nested row, set TreeViewItem.IsSelected on its BinaryTreeListViewItem. The row must already have been created, which it is once the control has been loaded.

Example
// Select the first top-level row once the window is on screen.
tree.Loaded += (sender, e) => tree.SelectNodeByIndex(0);
See also

SelectNodesByIndices

public void SelectNodesByIndices(IEnumerable<int> indices)

Selects several top-level rows by their positions, then scrolls the first top-level row into view.

Parameters
indices
The zero-based positions of the rows among the top-level rows. Positions out of range are ignored; null or an empty sequence does nothing.
Remarks

With IsMultiSelectionEnabled on, every row asked for is selected and held in MultiSelectedItems, just as if the user had Ctrl+clicked each one. With it off, the tree holds one selected row, so the row left selected is the last valid position.

Example
tree.IsMultiSelectionEnabled = true;
tree.SelectNodesByIndices(new[] { 0, 2, 3 });   // three rows selected together

SetSortMemberPath static

public static void SetSortMemberPath(DependencyObject column, string path)

Sets the name of the property a column is sorted by.

Parameters
column
The column, usually a GridViewColumn. Ignored when null.
path
The property of each row object to sort by, such as "Status" or "Owner.Name".
Remarks

Needed only for columns that draw their cells with a GridViewColumn.CellTemplate. A path set here wins over the column's GridViewColumn.DisplayMemberBinding.

Example
GridViewColumn status = new GridViewColumn { Header = "Status", CellTemplate = statusTemplate };
BinaryTreeListView.SetSortMemberPath(status, "Status");
tree.Columns.Add(status);

SortByColumn

public void SortByColumn(GridViewColumn column, ListSortDirection direction)

Sorts every branch of the tree by one column.

Parameters
column
The column to sort by. It needs a GridViewColumn.DisplayMemberBinding or a sort member path (SetSortMemberPath); a column with neither is ignored.
direction
The direction to sort in.
Remarks

Works whether or not AllowsColumnSorting is on, so a tree can open already sorted while the headings stay unclickable. Each branch is sorted within itself, so children stay under their parents.

A bound tree is sorted through each level's collection view, leaving your collections untouched. A built tree has its nodes put in order in place.

Example
// Open with the largest folders first.
tree.SortByColumn(tree.Columns[2], ListSortDirection.Descending);
See also

Events

ColumnReordered

public event EventHandler ColumnReordered

Occurs after a column has moved: dragged to a new place by the user, or moved in code with Move on Columns.

Remarks

Read the new order from Columns – to save the user's layout, for example. TreeListViewColumnIndex has already been updated when the event is raised.

Example
tree.ColumnReordered += (sender, e) =>
{
    // Remember the user's column order, by heading.
    Settings.ColumnOrder = string.Join("|", tree.Columns.Select(c => c.Header));
};

ColumnSorted

public event EventHandler ColumnSorted

Occurs after the rows have been sorted by a column, by a click on its heading or by SortByColumn.

Remarks

SortedColumn and SortDirection hold the new sort when the event is raised.

Example
tree.ColumnSorted += (sender, e) =>
{
    statusText.Text = "Sorted by " + tree.SortedColumn.Header
        + (tree.SortDirection == ListSortDirection.Ascending ? ", A to Z" : ", Z to A");
};

Fields

AllowsColumnReorderProperty static

public static readonly DependencyProperty AllowsColumnReorderProperty

Identifies the AllowsColumnReorder dependency property.

AllowsColumnSortingProperty static

public static readonly DependencyProperty AllowsColumnSortingProperty

Identifies the AllowsColumnSorting dependency property.

AlternateRowBackgroundBrushProperty static

public static readonly DependencyProperty AlternateRowBackgroundBrushProperty

Identifies the AlternateRowBackgroundBrush dependency property.

CollapseButtonImageProperty static

public static readonly DependencyProperty CollapseButtonImageProperty

Identifies the CollapseButtonImage dependency property.

ColumnHeaderBackgroundBrushProperty static

public static readonly DependencyProperty ColumnHeaderBackgroundBrushProperty

Identifies the ColumnHeaderBackgroundBrush dependency property.

ColumnHeaderBorderBrushProperty static

public static readonly DependencyProperty ColumnHeaderBorderBrushProperty

Identifies the ColumnHeaderBorderBrush dependency property.

ColumnHeaderForegroundBrushProperty static

public static readonly DependencyProperty ColumnHeaderForegroundBrushProperty

Identifies the ColumnHeaderForegroundBrush dependency property.

ColumnHeaderHeightProperty static

public static readonly DependencyProperty ColumnHeaderHeightProperty

Identifies the ColumnHeaderHeight dependency property.

ColumnHeaderHoverBackgroundBrushProperty static

public static readonly DependencyProperty ColumnHeaderHoverBackgroundBrushProperty

Identifies the ColumnHeaderHoverBackgroundBrush dependency property.

ColumnHeaderPressedBackgroundBrushProperty static

public static readonly DependencyProperty ColumnHeaderPressedBackgroundBrushProperty

Identifies the ColumnHeaderPressedBackgroundBrush dependency property.

ColumnReorderIndicatorBrushProperty static

public static readonly DependencyProperty ColumnReorderIndicatorBrushProperty

Identifies the ColumnReorderIndicatorBrush dependency property.

ExpandButtonImageProperty static

public static readonly DependencyProperty ExpandButtonImageProperty

Identifies the ExpandButtonImage dependency property.

ExpandCollapseBorderBrushProperty static

public static readonly DependencyProperty ExpandCollapseBorderBrushProperty

Identifies the ExpandCollapseBorderBrush dependency property.

ExpandCollapseButtonImageStretchProperty static

public static readonly DependencyProperty ExpandCollapseButtonImageStretchProperty

Identifies the ExpandCollapseButtonImageStretch dependency property.

ExpandCollapseControlFillBrushProperty static

public static readonly DependencyProperty ExpandCollapseControlFillBrushProperty

Identifies the ExpandCollapseControlFillBrush dependency property.

ExpandCollapsePlusMinusBrushProperty static

public static readonly DependencyProperty ExpandCollapsePlusMinusBrushProperty

Identifies the ExpandCollapsePlusMinusBrush dependency property.

ExpanderGlyphProperty static

public static readonly DependencyProperty ExpanderGlyphProperty

Identifies the ExpanderGlyph dependency property.

InactiveSelectionBackgroundBrushProperty static

public static readonly DependencyProperty InactiveSelectionBackgroundBrushProperty

Identifies the InactiveSelectionBackgroundBrush dependency property.

InactiveSelectionForegroundBrushProperty static

public static readonly DependencyProperty InactiveSelectionForegroundBrushProperty

Identifies the InactiveSelectionForegroundBrush dependency property.

IsMultiSelectionEnabledProperty static

public static readonly DependencyProperty IsMultiSelectionEnabledProperty = DependencyProperty.Register("IsMultiSelectionEnabled", typeof(bool), typeof(BinaryTreeListView), new UIPropertyMetadata(false, (o, e)

Identifies the IsMultiSelectionEnabled dependency property.

IsNodesConnectingLineDottedProperty static

public static readonly DependencyProperty IsNodesConnectingLineDottedProperty

Identifies the IsNodesConnectingLineDotted dependency property.

IsNodesConnectingLineVisibleProperty static

public static readonly DependencyProperty IsNodesConnectingLineVisibleProperty

Identifies the IsNodesConnectingLineVisible dependency property.

IsShiftMultiSelectionEnabledProperty static

public static readonly DependencyProperty IsShiftMultiSelectionEnabledProperty = DependencyProperty.Register("IsShiftMultiSelectionEnabled", typeof(bool), typeof(BinaryTreeListView), new UIPropertyMetadata(false, (o, e)

Identifies the IsShiftMultiSelectionEnabled dependency property.

MouseOverBackgroundBrushProperty static

public static readonly DependencyProperty MouseOverBackgroundBrushProperty

Identifies the MouseOverBackgroundBrush dependency property.

MouseOverForegroundBrushProperty static

public static readonly DependencyProperty MouseOverForegroundBrushProperty

Identifies the MouseOverForegroundBrush dependency property.

NodesConnectingLineBrushProperty static

public static readonly DependencyProperty NodesConnectingLineBrushProperty

Identifies the NodesConnectingLineBrush dependency property.

RenderCollapseExpandVisualAlwaysInTheFirstColumnProperty static

public static readonly DependencyProperty RenderCollapseExpandVisualAlwaysInTheFirstColumnProperty

Identifies the RenderCollapseExpandVisualAlwaysInTheFirstColumn dependency property.

RowBackgroundBrushProperty static

public static readonly DependencyProperty RowBackgroundBrushProperty

Identifies the RowBackgroundBrush dependency property.

RowSeparatorBrushProperty static

public static readonly DependencyProperty RowSeparatorBrushProperty

Identifies the RowSeparatorBrush dependency property.

SelectionBackgroundBrushProperty static

public static readonly DependencyProperty SelectionBackgroundBrushProperty

Identifies the SelectionBackgroundBrush dependency property.

SelectionForegroundBrushProperty static

public static readonly DependencyProperty SelectionForegroundBrushProperty

Identifies the SelectionForegroundBrush dependency property.

SortDirectionProperty static

public static readonly DependencyProperty SortDirectionProperty

Identifies the SortDirection dependency property.

SortGlyphBrushProperty static

public static readonly DependencyProperty SortGlyphBrushProperty

Identifies the SortGlyphBrush dependency property.

SortMemberPathProperty static

public static readonly DependencyProperty SortMemberPathProperty

Identifies the SortMemberPath attached property: the name of the property a column is sorted by, for a column that draws its cells with a template and so has no GridViewColumn.DisplayMemberBinding to read one from.

SortedColumnProperty static

public static readonly DependencyProperty SortedColumnProperty

Identifies the SortedColumn dependency property.

ThemeProperty static

public static readonly DependencyProperty ThemeProperty

Identifies the Theme dependency property.

TreeListViewColumnIndexProperty static

public static readonly DependencyProperty TreeListViewColumnIndexProperty

Identifies the TreeListViewColumnIndex dependency property.

TreeListViewColumnProperty static

public static readonly DependencyProperty TreeListViewColumnProperty

Identifies the TreeListViewColumn dependency property.

TreeListViewItemIsRenderedWithRoundedCornerProperty static

public static readonly DependencyProperty TreeListViewItemIsRenderedWithRoundedCornerProperty

Identifies the TreeListViewItemIsRenderedWithRoundedCorner dependency property.