BinaryTreeListView
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.
- Bind it. Set
ItemsControl.ItemsSourceto your top-level objects, and setItemsControl.ItemTemplateto aHierarchicalDataTemplatewhoseItemsSourcenames each object's children. The columns' bindings are evaluated against each object. - Build it. Add
BinaryTreeListViewItemnodes toItemsControl.Items, each with its row object inHeaderand its child nodes in its ownItems.
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 | |
|---|---|
BinaryTreeListView | Creates a tree list view with no columns and no rows. |
| Properties | |
AllowsColumnReorder | Gets or sets whether the user can move a column by dragging its heading. |
AllowsColumnSorting | Gets or sets whether clicking a column heading sorts the rows by that column. |
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. |
CollapseButtonImage | Gets or sets a picture to draw as the expander of an expanded row, in place of the shape the control draws. |
ColumnHeaderBackgroundBrush | Gets or sets the fill behind the column headings. |
ColumnHeaderBorderBrush | Gets or sets the colour of the edge drawn to the right of and under each column heading. |
ColumnHeaderForegroundBrush | Gets or sets the colour of the column headings' text. |
ColumnHeaderHeight | Gets or sets the height of the column heading row. |
ColumnHeaderHoverBackgroundBrush | Gets or sets the fill behind a column heading while the pointer is over it. |
ColumnHeaderPressedBackgroundBrush | Gets or sets the fill behind a column heading while it is being pressed. |
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. |
Columns | Gets the columns the rows are laid out in. |
ExpandButtonImage | Gets or sets a picture to draw as the expander of a collapsed row, in place of the shape the control draws. |
ExpandCollapseBorderBrush | Gets or sets the colour of the box drawn around the expander's mark. |
ExpandCollapseButtonImageStretch | Gets or sets how ExpandButtonImage and CollapseButtonImage are
sized in the expander. |
ExpandCollapseControlFillBrush | Gets or sets the colour inside the box of the boxed expander shapes,
BinaryTreeListViewExpanderGlyph.PlusMinus and
BinaryTreeListViewExpanderGlyph.BoxedChevron. |
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. |
ExpanderGlyph | Gets or sets the shape the expander is drawn as. |
InactiveSelectionBackgroundBrush | Gets or sets the background of a selected row while the control does not have focus. |
InactiveSelectionForegroundBrush | Gets or sets the text colour of a selected row while the control does not have focus. |
IsMultiSelectionEnabled | Gets or sets whether the user can hold several rows selected at once. |
IsNodesConnectingLineDotted | Gets or sets whether the lines that join the rows are drawn dotted rather than solid. |
IsNodesConnectingLineVisible | Gets or sets whether lines are drawn joining each row to its parent and its siblings. |
IsShiftMultiSelectionEnabled | Gets or sets whether Shift+click selects a range of rows. |
MouseOverBackgroundBrush | Gets or sets the row background drawn while the pointer is over it. |
MouseOverForegroundBrush | Gets or sets the row foreground drawn while the pointer is over it. |
MultiSelectedItems | Gets the rows the user has selected while multi-selection is on. |
NodesConnectingLineBrush | Gets or sets the colour of the lines that join the rows of the tree. |
RenderCollapseExpandVisualAlwaysInTheFirstColumn | Gets or sets whether the tree is always drawn in the left-most column, whichever column
TreeListViewColumn names. |
RowBackgroundBrush | Gets or sets the background of the first, third, fifth row and so on, counting the rows as they are drawn on screen. |
RowSeparatorBrush | Gets or sets the colour of a thin line drawn under every row. |
SelectionBackgroundBrush | Gets or sets the background of a selected row while the control has focus. |
SelectionForegroundBrush | Gets or sets the text colour of a selected row while the control has focus. |
SortDirection | Gets the direction SortedColumn is sorted in. |
SortGlyphBrush | Gets or sets the colour of the arrow drawn over the heading of the column the rows are sorted by. |
SortedColumn | Gets the column the rows are sorted by. |
Theme | Gets or sets the built-in colour scheme the control is drawn in. |
TreeListViewColumn | Gets or sets the column that carries the tree: the indent, the expander and the connecting lines. |
TreeListViewColumnIndex | Gets or sets the position in Columns of the column that carries the tree. |
TreeListViewItemIsRenderedWithRoundedCorner | Gets or sets whether each row's background – its selection, hover and stripe colour – is drawn with rounded corners. |
| Methods | |
ClearColumnSort | Stops sorting by a column and removes the sort arrow. |
CollapseAllNodes | Collapses every row in the tree, at every level, and scrolls back to the first row. |
ExpandAllNodes | Expands every row in the tree, at every level. |
ExpandNodeByIndex | Expands one top-level row and every row beneath it. |
ExpandNodesByIndices | Expands several top-level rows, each with every row beneath it, then scrolls the first top-level row into view. |
GetContainerForItemOverride | Creates the row that shows one bound item: a BinaryTreeListViewItem. |
GetSortMemberPath | Gets the name of the property a column is sorted by. |
IsItemItsOwnContainerOverride | Tells the control whether an item is already a row, and so needs no row of its own. |
OnApplyTemplate | Applies the control's template. |
OnItemsChanged | Lays the alternate-row stripes again when top-level rows are added, removed or moved. |
RefreshRowDecorations | Draws the connecting lines and row separators of every row on screen again. |
RefreshRowStriping | Lays the alternating row backgrounds again, in the order the rows are drawn. |
SelectNodeByIndex | Selects a top-level row by its position. |
SelectNodesByIndices | Selects several top-level rows by their positions, then scrolls the first top-level row into view. |
SetSortMemberPath | Sets the name of the property a column is sorted by. |
SortByColumn | Sorts every branch of the tree by one column. |
| Events | |
ColumnReordered | Occurs after a column has moved: dragged to a new place by the user, or moved in code with
Move on Columns. |
ColumnSorted | Occurs after the rows have been sorted by a column, by a click on its heading or by
SortByColumn. |
| Fields | |
AllowsColumnReorderProperty | Identifies the AllowsColumnReorder dependency property. |
AllowsColumnSortingProperty | Identifies the AllowsColumnSorting dependency property. |
AlternateRowBackgroundBrushProperty | Identifies the AlternateRowBackgroundBrush dependency property. |
CollapseButtonImageProperty | Identifies the CollapseButtonImage dependency property. |
ColumnHeaderBackgroundBrushProperty | Identifies the ColumnHeaderBackgroundBrush dependency property. |
ColumnHeaderBorderBrushProperty | Identifies the ColumnHeaderBorderBrush dependency property. |
ColumnHeaderForegroundBrushProperty | Identifies the ColumnHeaderForegroundBrush dependency property. |
ColumnHeaderHeightProperty | Identifies the ColumnHeaderHeight dependency property. |
ColumnHeaderHoverBackgroundBrushProperty | Identifies the ColumnHeaderHoverBackgroundBrush dependency property. |
ColumnHeaderPressedBackgroundBrushProperty | Identifies the ColumnHeaderPressedBackgroundBrush dependency property. |
ColumnReorderIndicatorBrushProperty | Identifies the ColumnReorderIndicatorBrush dependency property. |
ExpandButtonImageProperty | Identifies the ExpandButtonImage dependency property. |
ExpandCollapseBorderBrushProperty | Identifies the ExpandCollapseBorderBrush dependency property. |
ExpandCollapseButtonImageStretchProperty | Identifies the ExpandCollapseButtonImageStretch dependency property. |
ExpandCollapseControlFillBrushProperty | Identifies the ExpandCollapseControlFillBrush dependency property. |
ExpandCollapsePlusMinusBrushProperty | Identifies the ExpandCollapsePlusMinusBrush dependency property. |
ExpanderGlyphProperty | Identifies the ExpanderGlyph dependency property. |
InactiveSelectionBackgroundBrushProperty | Identifies the InactiveSelectionBackgroundBrush dependency property. |
InactiveSelectionForegroundBrushProperty | Identifies the InactiveSelectionForegroundBrush dependency property. |
IsMultiSelectionEnabledProperty | Identifies the IsMultiSelectionEnabled dependency property. |
IsNodesConnectingLineDottedProperty | Identifies the IsNodesConnectingLineDotted dependency property. |
IsNodesConnectingLineVisibleProperty | Identifies the IsNodesConnectingLineVisible dependency property. |
IsShiftMultiSelectionEnabledProperty | Identifies the IsShiftMultiSelectionEnabled dependency property. |
MouseOverBackgroundBrushProperty | Identifies the MouseOverBackgroundBrush dependency property. |
MouseOverForegroundBrushProperty | Identifies the MouseOverForegroundBrush dependency property. |
NodesConnectingLineBrushProperty | Identifies the NodesConnectingLineBrush dependency property. |
RenderCollapseExpandVisualAlwaysInTheFirstColumnProperty | Identifies the RenderCollapseExpandVisualAlwaysInTheFirstColumn dependency property. |
RowBackgroundBrushProperty | Identifies the RowBackgroundBrush dependency property. |
RowSeparatorBrushProperty | Identifies the RowSeparatorBrush dependency property. |
SelectionBackgroundBrushProperty | Identifies the SelectionBackgroundBrush dependency property. |
SelectionForegroundBrushProperty | Identifies the SelectionForegroundBrush dependency property. |
SortDirectionProperty | Identifies the SortDirection dependency property. |
SortGlyphBrushProperty | Identifies the SortGlyphBrush dependency property. |
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 | Identifies the SortedColumn dependency property. |
ThemeProperty | Identifies the Theme dependency property. |
TreeListViewColumnIndexProperty | Identifies the TreeListViewColumnIndex dependency property. |
TreeListViewColumnProperty | Identifies the TreeListViewColumn dependency property. |
TreeListViewItemIsRenderedWithRoundedCornerProperty | Identifies the TreeListViewItemIsRenderedWithRoundedCorner dependency property. |
Constructors
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
Gets or sets whether the user can move a column by dragging its heading.
- Value
trueto 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
Gets or sets whether clicking a column heading sorts the rows by that column.
- Value
trueto sort on click. The default isfalse.
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
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
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 byExpanderGlyph.
Remarks
See ExpandButtonImage, which works the same way for collapsed rows.
ColumnHeaderBackgroundBrush
Gets or sets the fill behind the column headings.
- Value
- The default is a near-white (
#FCFDFF); eachThemesets its own.
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
Gets or sets the colour of the column headings' text.
- Value
- The default is a dark slate (
#242F3E).
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
Gets or sets the fill behind a column heading while the pointer is over it.
- Value
- The default is a pale blue (
#E9F2FE).
ColumnHeaderPressedBackgroundBrush
Gets or sets the fill behind a column heading while it is being pressed.
- Value
- The default is a light blue (
#C6DBF7).
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
Gets the columns the rows are laid out in.
- Value
- The control's column collection, never
null. Add aGridViewColumnfor each column, with aGridViewColumn.DisplayMemberBindingor aGridViewColumn.CellTemplate, aGridViewColumn.Headerand, if you like, aGridViewColumn.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
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 byExpanderGlyph.
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
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.PlusMinusandBinaryTreeListViewExpanderGlyph.BoxedChevron, draw a box.
See also
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
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
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
Themeuses its accent colour.
See also
ExpanderGlyph
Gets or sets the shape the expander is drawn as.
- Value
- One of the five
BinaryTreeListViewExpanderGlyphshapes. The default isBinaryTreeListViewExpanderGlyph.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
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
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
Gets or sets whether the user can hold several rows selected at once.
- Value
trueto let Ctrl+click select and deselect rows while keeping the others. The default isfalse.
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
Gets or sets whether the lines that join the rows are drawn dotted rather than solid.
- Value
truefor dotted lines, as in the classic Windows tree view. The default isfalse.
See also
IsNodesConnectingLineVisible
Gets or sets whether lines are drawn joining each row to its parent and its siblings.
- Value
trueto draw the lines; the default. They are drawn in the tree column only, inNodesConnectingLineBrush.
See also
IsShiftMultiSelectionEnabled
Gets or sets whether Shift+click selects a range of rows.
- Value
trueto allow range selection. The default isfalse. It takes effect only whileIsMultiSelectionEnabledis 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
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
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
Gets the rows the user has selected while multi-selection is on.
- Value
- The selected rows. Each entry is the row's
BinaryTreeListViewItem; itsHeader(or itsDataContextwhen 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
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
Themesets its own.
See also
RenderCollapseExpandVisualAlwaysInTheFirstColumn
Gets or sets whether the tree is always drawn in the left-most column, whichever column
TreeListViewColumn names.
- Value
trueto keep the tree in the first column on screen, even after the user drags another column in front of it. The default isfalse: the tree stays in its column wherever that column is moved.
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
Gets or sets the colour of a thin line drawn under every row.
- Value
- The default is
null: no line. EachThemesets 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
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
Themesets its own.
See also
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
Gets the direction SortedColumn is sorted in.
- Value
ListSortDirection.AscendingorListSortDirection.Descending. Meaningful only whileSortedColumnis set.
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); eachThemesets its own.
SortedColumn
Gets the column the rows are sorted by.
- Value
- The column, or
nullwhen the rows are in the order they were added or bound.
See also
Theme
Gets or sets the built-in colour scheme the control is drawn in.
- Value
- One of the
BinaryTreeListViewThemeschemes. The default isBinaryTreeListViewTheme.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
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 isnull– 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
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
Gets or sets whether each row's background – its selection, hover and stripe colour – is drawn with rounded corners.
- Value
truefor corners rounded by four pixels; the default.falsefor square ones.
Methods
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
Collapses every row in the tree, at every level, and scrolls back to the first row.
See also
ExpandAllNodes
Expands every row in the tree, at every level.
Parameters
shouldScrollBackToToptrueto scroll the first top-level row back into view afterwards;falseto 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
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
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;
nullor an empty sequence does nothing.
See also
GetContainerForItemOverride
Creates the row that shows one bound item: a BinaryTreeListViewItem.
Returns
A new, empty BinaryTreeListViewItem.
GetSortMemberPath static
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
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
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
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
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
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
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
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;
nullor 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 togetherSetSortMemberPath static
Sets the name of the property a column is sorted by.
Parameters
column- The column, usually a
GridViewColumn. Ignored whennull. 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
Sorts every branch of the tree by one column.
Parameters
column- The column to sort by. It needs a
GridViewColumn.DisplayMemberBindingor 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
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
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
Identifies the AllowsColumnReorder dependency property.
AllowsColumnSortingProperty static
Identifies the AllowsColumnSorting dependency property.
AlternateRowBackgroundBrushProperty static
Identifies the AlternateRowBackgroundBrush dependency property.
CollapseButtonImageProperty static
Identifies the CollapseButtonImage dependency property.
ColumnHeaderBackgroundBrushProperty static
Identifies the ColumnHeaderBackgroundBrush dependency property.
ColumnHeaderBorderBrushProperty static
Identifies the ColumnHeaderBorderBrush dependency property.
ColumnHeaderForegroundBrushProperty static
Identifies the ColumnHeaderForegroundBrush dependency property.
ColumnHeaderHeightProperty static
Identifies the ColumnHeaderHeight dependency property.
ColumnHeaderHoverBackgroundBrushProperty static
Identifies the ColumnHeaderHoverBackgroundBrush dependency property.
ColumnHeaderPressedBackgroundBrushProperty static
Identifies the ColumnHeaderPressedBackgroundBrush dependency property.
ColumnReorderIndicatorBrushProperty static
Identifies the ColumnReorderIndicatorBrush dependency property.
ExpandButtonImageProperty static
Identifies the ExpandButtonImage dependency property.
ExpandCollapseBorderBrushProperty static
Identifies the ExpandCollapseBorderBrush dependency property.
ExpandCollapseButtonImageStretchProperty static
Identifies the ExpandCollapseButtonImageStretch dependency property.
ExpandCollapseControlFillBrushProperty static
Identifies the ExpandCollapseControlFillBrush dependency property.
ExpandCollapsePlusMinusBrushProperty static
Identifies the ExpandCollapsePlusMinusBrush dependency property.
ExpanderGlyphProperty static
Identifies the ExpanderGlyph dependency property.
InactiveSelectionBackgroundBrushProperty static
Identifies the InactiveSelectionBackgroundBrush dependency property.
InactiveSelectionForegroundBrushProperty static
Identifies the InactiveSelectionForegroundBrush dependency property.
IsMultiSelectionEnabledProperty static
Identifies the IsMultiSelectionEnabled dependency property.
IsNodesConnectingLineDottedProperty static
Identifies the IsNodesConnectingLineDotted dependency property.
IsNodesConnectingLineVisibleProperty static
Identifies the IsNodesConnectingLineVisible dependency property.
IsShiftMultiSelectionEnabledProperty static
Identifies the IsShiftMultiSelectionEnabled dependency property.
MouseOverBackgroundBrushProperty static
Identifies the MouseOverBackgroundBrush dependency property.
MouseOverForegroundBrushProperty static
Identifies the MouseOverForegroundBrush dependency property.
NodesConnectingLineBrushProperty static
Identifies the NodesConnectingLineBrush dependency property.
RenderCollapseExpandVisualAlwaysInTheFirstColumnProperty static
Identifies the RenderCollapseExpandVisualAlwaysInTheFirstColumn dependency property.
RowBackgroundBrushProperty static
Identifies the RowBackgroundBrush dependency property.
RowSeparatorBrushProperty static
Identifies the RowSeparatorBrush dependency property.
SelectionBackgroundBrushProperty static
Identifies the SelectionBackgroundBrush dependency property.
SelectionForegroundBrushProperty static
Identifies the SelectionForegroundBrush dependency property.
SortDirectionProperty static
Identifies the SortDirection dependency property.
SortGlyphBrushProperty static
Identifies the SortGlyphBrush dependency property.
SortMemberPathProperty static
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
Identifies the SortedColumn dependency property.
ThemeProperty static
Identifies the Theme dependency property.
TreeListViewColumnIndexProperty static
Identifies the TreeListViewColumnIndex dependency property.
TreeListViewColumnProperty static
Identifies the TreeListViewColumn dependency property.
TreeListViewItemIsRenderedWithRoundedCornerProperty static
Identifies the TreeListViewItemIsRenderedWithRoundedCorner dependency property.