OrganizedTree
An organisation chart: a tree of people, teams or items drawn as cards joined by lines, from the root at the top down to its leaves – or bottom up, left to right or right to left.
public partial class OrganizedTree : ContentControl
Inherits from / implements: ContentControl
Remarks
Use it to show who reports to whom, how a business is divided into divisions and teams, a product's bill of materials, a family tree, or any parent-and-child structure that reads best as a picture rather than an indented list.
Nodes
Each box on the chart is an OrganizedTreeNode. Put the top-level nodes in
Nodes and each node's children in its own
OrganizedTreeNode.Children, as deep as you like; more than one top-level node draws
several trees side by side. A node can be drawn in either of two ways:
- As a built-in card. Give the node a
OrganizedTreeNode.TitleandOrganizedTreeNode.Subtitle– a name and a role, say – and optionally a picture and an accent colour. The chart draws a rounded card with a coloured stripe, a round avatar showing the picture or the person's initials, and the two lines of text. The cards areNodeCardWidthbyNodeCardHeight. - As an element of your own. Give the node any
FrameworkElement– aBorderholding a photo and three lines of text, aButton, a user control – with an explicit width and height. The chart places it and joins it to the rest.
The two can be mixed in one chart.
Drawing the chart
The chart is drawn when RenderTree is called. Call it once the nodes are in
Nodes, and again after adding, removing or rearranging nodes or changing what a card
shows: the node lists are plain lists, so the chart cannot see them change. Properties of the
chart itself – the spacing, the direction, the connector style, the colours – redraw it as they are
set.
The chart grows to the size of the tree and has no scroll bars of its own: put it in a
ScrollViewer with both scroll bars on Auto so that a large organisation can be
panned. ZoomFactor, ZoomToFit and Ctrl with the mouse wheel scale it,
and CenterOnNode brings one node into the middle of the view. The control's
Control.Padding is left clear around the chart.
Layout and connectors
TreeLayoutDirection chooses which way the tree grows.
SpacingBetweenChildNodeToParent sets the gap between one level and the next, and
SpacingBetweenSiblingNodes the gap between neighbours; a parent is centred over its
children. The lines are drawn in one of four shapes (ConnectorStyle), solid or dashed,
and can carry small round ports where they meet the cards, arrowheads, and direction
chevrons.
Interaction
A click selects a node (SelectedNode, SelectedNodeChanged) and
draws a ring around it; the arrow keys then move the selection around the chart. The path from the
node under the pointer – or, with none, the selected node – up to its root is drawn in
PathHighlightBrush. With IsCollapseExpandOfNodesEnabled turned on, every
parent gets a round button that folds its branch away, with a badge counting the nodes it
hides.
Appearance
Every colour is a brush property of the chart, and a card can take its own accent through
OrganizedTreeNode.AccentBrush. The default given for each brush is the one used with no
Binarymission skin in force; while a skin is applied through BinarySkinManager it supplies
the card, line, selection and expander colours, and any brush set on the chart itself still wins.
With no skin the connecting lines default to a mid grey, which shows on light and dark surfaces
alike.
Print() sends the chart to a printer and Export returns it as a
bitmap.
Examples
A chart in XAML, inside a scroll viewer, with the nodes built in the code-behind. The
assembly is Binarymission.WPF.Controls.TreeControls.OrganizedTreeView.
<Window x:Class="People.OrgChartWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:org="clr-namespace:Binarymission.WPF.Controls.TreeControls;assembly=Binarymission.WPF.Controls.TreeControls.OrganizedTreeView"
Title="Organisation" Width="1000" Height="640">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<org:OrganizedTree x:Name="orgChart"
Padding="24"
ConnectorStyle="RoundedElbow"
ConnectingLineBrush="#9AA5B1"
ConnectingLineThickness="2"
SpacingBetweenChildNodeToParent="48"
SpacingBetweenSiblingNodes="16"
IsCollapseExpandOfNodesEnabled="True"
SelectedNodeChanged="OnSelectedPersonChanged" />
</ScrollViewer>
</Window>using System.Windows;
using System.Windows.Media;
using Binarymission.WPF.Controls.TreeControls;
public partial class OrgChartWindow : Window
{
public OrgChartWindow()
{
InitializeComponent();
var ceo = new OrganizedTreeNode("Helen Carter", "Chief Executive");
var finance = new OrganizedTreeNode("Raj Patel", "Finance Director", Color.FromRgb(16, 150, 120));
var sales = new OrganizedTreeNode("Sophie Martin", "Sales Director", Color.FromRgb(214, 120, 30));
finance.Children.Add(new OrganizedTreeNode("Tom Hughes", "Financial Controller"));
finance.Children.Add(new OrganizedTreeNode("Aisha Khan", "Payroll Manager"));
sales.Children.Add(new OrganizedTreeNode("Ben Wright", "Key Accounts") { Data = 1042 });
sales.Children.Add(new OrganizedTreeNode("Lucy Evans", "Inside Sales") { Data = 1077 });
ceo.Children.Add(finance);
ceo.Children.Add(sales);
orgChart.Nodes.Add(ceo);
orgChart.RenderTree();
}
private void OnSelectedPersonChanged(object sender, RoutedPropertyChangedEventArgs<OrganizedTreeNode> e)
{
if (e.NewValue != null)
{
Title = "Organisation - " + e.NewValue.Title;
}
}
}See also
Members at a glance
| Constructors | |
|---|---|
OrganizedTree | Creates an empty chart. |
| Properties | |
CollapseExpandAnimationDuration | Gets or sets how long the collapse and expand animation lasts. |
CollapsedChildCountBrush | Gets or sets the fill of the badge that counts the nodes hidden under a collapsed node. |
ConnectingLineBrush | Gets or sets the colour of the connecting lines – and, unless they are given colours of their own, of the ports, arrowheads, chevrons and collapse / expand buttons. |
ConnectingLineStrokeDashArray | Gets or sets the pattern of dashes and gaps the connecting lines are drawn with. |
ConnectingLineStyle | Gets or sets a Style for the connecting lines, for effects the line properties do not
offer. |
ConnectingLineThickness | Gets or sets the width of the connecting lines. |
ConnectorArrowBrush | Gets or sets the fill of the arrowheads drawn when ShowConnectorArrows is on. |
ConnectorChevronBrush | Gets or sets the colour of the direction chevrons. |
ConnectorChevronSize | Gets or sets the size of each direction chevron, from the tip of one arm to the tip of the other. |
ConnectorChevronThickness | Gets or sets the width of the strokes the direction chevrons are drawn with. |
ConnectorChevrons | Gets or sets the chevrons drawn part-way along each connector to show which way the relationship runs. |
ConnectorCornerRadius | Gets or sets how rounded the corners of ConnectorStyle.RoundedElbow connectors are. |
ConnectorPortBrush | Gets or sets the fill of the connector ports. |
ConnectorPortSize | Gets or sets the diameter of the connector ports. |
ConnectorPortStrokeBrush | Gets or sets the colour of a ring drawn around each connector port – white, say, to lift the ports off the lines. |
ConnectorPortStrokeThickness | Gets or sets the width of the ring around each connector port. |
ConnectorStyle | Gets or sets the shape of the lines joining parents to children. |
ExpanderButtonBackground | Gets or sets the face colour of the built-in collapse / expand buttons. |
ExpanderButtonBorderBrush | Gets or sets the ring colour of the built-in collapse / expand buttons, which is also the fill of a collapsed button. |
ExpanderButtonBorderThickness | Gets or sets the width of the ring around the built-in collapse / expand buttons. |
ExpanderButtonGlyphBrush | Gets or sets the colour of the plus and minus signs on the built-in collapse / expand buttons. |
ExpanderButtonSize | Gets or sets the diameter of the collapse / expand buttons. |
ExpanderButtonStyle | Gets or sets a Style for the collapse / expand buttons, replacing the chart's own
round buttons. |
IsCollapseExpandAnimated | Gets or sets whether nodes fade and grow into view when a branch is expanded, and fade and shrink away when it is collapsed. |
IsCollapseExpandOfNodesEnabled | Gets or sets whether each parent node has a button that collapses its branch out of sight and expands it again. |
IsMouseWheelZoomEnabled | Gets or sets whether holding Ctrl and turning the mouse wheel zooms the chart in and out around the pointer. |
IsNodeHoverEffectEnabled | Gets or sets whether a node rises slightly, and a card's shadow deepens, while the pointer is over it. |
IsNodeSelectionEnabled | Gets or sets whether the user can select a node by clicking it or with the arrow keys. |
IsPathToRootHighlighted | Gets or sets whether the line of command from a node up to the top of the chart is drawn in
PathHighlightBrush. |
IsShowConnectingLines | Gets or sets whether the lines joining parents to children are drawn. |
IsUsingCustomLineStyle | Gets or sets whether the connecting lines are drawn with ConnectingLineStyle rather
than with the line properties. |
NodeCardAccentBrush | Gets or sets the colour of the stripe and avatar on the built-in cards whose node has no
OrganizedTreeNode.AccentBrush of its own. |
NodeCardBackground | Gets or sets the fill of the built-in cards. |
NodeCardBorderBrush | Gets or sets the colour of the thin outline around the built-in cards. |
NodeCardCornerRadius | Gets or sets how rounded the corners of the built-in cards are. |
NodeCardHeight | Gets or sets the height of the built-in cards. |
NodeCardSubtitleBrush | Gets or sets the colour of the second line of text on the built-in cards. |
NodeCardTitleBrush | Gets or sets the colour of the first, bold line of text on the built-in cards. |
NodeCardWidth | Gets or sets the width of the built-in cards. |
NodeSelectionBrush | Gets or sets the colour of the ring drawn around the selected node. |
NodeSelectionThickness | Gets or sets the width of the ring drawn around the selected node. |
Nodes | Gets or sets the top-level nodes of the chart – usually one, the head of the organisation; several draw several trees side by side. |
PathHighlightBrush | Gets or sets the colour of the highlighted path from a node up to its root. |
SelectedNode | Gets or sets the node that is selected on the chart, ringed in NodeSelectionBrush. |
ShowCollapsedChildCount | Gets or sets whether a collapsed node's button carries a small badge counting the nodes hidden beneath it. |
ShowConnectorArrows | Gets or sets whether each connector ends in an arrowhead pointing at the child. |
ShowConnectorPorts | Gets or sets whether a small round dot is drawn at each point where a connector meets a card. |
ShowNodeCardAccentStripe | Gets or sets whether the built-in cards carry a stripe of the accent colour down their left edge. |
ShowNodeCardAvatar | Gets or sets whether the built-in cards show a round avatar with the node's picture or initials. |
ShowNodeCardShadow | Gets or sets whether the built-in cards cast a soft shadow below them. |
SpacingBetweenChildNodeToParent | Gets or sets the gap between a parent's card and its children's cards – the distance from one level of the chart to the next. |
SpacingBetweenSiblingNodes | Gets or sets the gap between neighbouring cards on the same level, and between one branch and the next. |
TreeLayoutDirection | Gets or sets which way the chart grows from its root nodes: down, up, to the right or to the left. |
ZoomFactor | Gets or sets the scale the chart is drawn at: 1 is actual size, 0.5 half size, 2 double. |
| Methods | |
CenterOnNode | Scrolls the enclosing ScrollViewer so that a node is in the middle of the visible
area – to show a search result, say. |
Export | Takes a picture of the whole chart, for saving to a file, pasting into a report or printing in a layout of your own. |
OnKeyDown | Moves the selection with the arrow keys and Home, and collapses or expands the selected node with Enter, Space, + and -. |
OnMouseWheel | Zooms the chart in or out by 10% around the pointer when Ctrl is held and
IsMouseWheelZoomEnabled is on. |
Print | Shows the print dialog and prints the whole chart, including the parts scrolled out of view, with margins of 84 logical pixels (7/8 inch) all round. |
Print | Shows the print dialog and prints the whole chart, including the parts scrolled out of view, with the margins you choose. |
RenderTree | Draws the chart from Nodes, laying out every node and drawing the lines, buttons and
selection again. |
ZoomToFit | Sets ZoomFactor so that the whole chart fits in the visible area, and scrolls back to
its top-left corner. |
| Events | |
SelectedNodeChanged | Occurs when the selected node changes – by a click, the keyboard, code, or a collapse that hides the selected node. |
| Fields | |
CollapseExpandAnimationDurationProperty | Identifies the CollapseExpandAnimationDuration dependency property. |
CollapsedChildCountBrushProperty | Identifies the CollapsedChildCountBrush dependency property. |
ConnectingLineBrushProperty | Identifies the ConnectingLineBrush dependency property. |
ConnectingLineStrokeDashArrayProperty | Identifies the ConnectingLineStrokeDashArray dependency property. |
ConnectingLineStyleProperty | Identifies the ConnectingLineStyle dependency property. |
ConnectingLineThicknessProperty | Identifies the ConnectingLineThickness dependency property. |
ConnectorArrowBrushProperty | Identifies the ConnectorArrowBrush dependency property. |
ConnectorChevronBrushProperty | Identifies the ConnectorChevronBrush dependency property. |
ConnectorChevronSizeProperty | Identifies the ConnectorChevronSize dependency property. |
ConnectorChevronThicknessProperty | Identifies the ConnectorChevronThickness dependency property. |
ConnectorChevronsProperty | Identifies the ConnectorChevrons dependency property. |
ConnectorCornerRadiusProperty | Identifies the ConnectorCornerRadius dependency property. |
ConnectorPortBrushProperty | Identifies the ConnectorPortBrush dependency property. |
ConnectorPortSizeProperty | Identifies the ConnectorPortSize dependency property. |
ConnectorPortStrokeBrushProperty | Identifies the ConnectorPortStrokeBrush dependency property. |
ConnectorPortStrokeThicknessProperty | Identifies the ConnectorPortStrokeThickness dependency property. |
ConnectorStyleProperty | Identifies the ConnectorStyle dependency property. |
ExpanderButtonBackgroundProperty | Identifies the ExpanderButtonBackground dependency property. |
ExpanderButtonBorderBrushProperty | Identifies the ExpanderButtonBorderBrush dependency property. |
ExpanderButtonBorderThicknessProperty | Identifies the ExpanderButtonBorderThickness dependency property. |
ExpanderButtonGlyphBrushProperty | Identifies the ExpanderButtonGlyphBrush dependency property. |
ExpanderButtonSizeProperty | Identifies the ExpanderButtonSize dependency property. |
ExpanderButtonStyleProperty | Identifies the ExpanderButtonStyle dependency property. |
IsCollapseExpandAnimatedProperty | Identifies the IsCollapseExpandAnimated dependency property. |
IsCollapseExpandOfNodesEnabledProperty | Identifies the IsCollapseExpandOfNodesEnabled dependency property. |
IsMouseWheelZoomEnabledProperty | Identifies the IsMouseWheelZoomEnabled dependency property. |
IsNodeHoverEffectEnabledProperty | Identifies the IsNodeHoverEffectEnabled dependency property. |
IsNodeSelectionEnabledProperty | Identifies the IsNodeSelectionEnabled dependency property. |
IsPathToRootHighlightedProperty | Identifies the IsPathToRootHighlighted dependency property. |
IsShowConnectingLinesProperty | Identifies the IsShowConnectingLines dependency property. |
IsUsingCustomLineStyleProperty | Identifies the IsUsingCustomLineStyle dependency property. |
NodeCardAccentBrushProperty | Identifies the NodeCardAccentBrush dependency property. |
NodeCardBackgroundProperty | Identifies the NodeCardBackground dependency property. |
NodeCardBorderBrushProperty | Identifies the NodeCardBorderBrush dependency property. |
NodeCardCornerRadiusProperty | Identifies the NodeCardCornerRadius dependency property. |
NodeCardHeightProperty | Identifies the NodeCardHeight dependency property. |
NodeCardSubtitleBrushProperty | Identifies the NodeCardSubtitleBrush dependency property. |
NodeCardTitleBrushProperty | Identifies the NodeCardTitleBrush dependency property. |
NodeCardWidthProperty | Identifies the NodeCardWidth dependency property. |
NodeSelectionBrushProperty | Identifies the NodeSelectionBrush dependency property. |
NodeSelectionThicknessProperty | Identifies the NodeSelectionThickness dependency property. |
NodesProperty | Identifies the Nodes dependency property. |
PathHighlightBrushProperty | Identifies the PathHighlightBrush dependency property. |
SelectedNodeChangedEvent | Identifies the SelectedNodeChanged routed event. |
SelectedNodeProperty | Identifies the SelectedNode dependency property. |
ShowCollapsedChildCountProperty | Identifies the ShowCollapsedChildCount dependency property. |
ShowConnectorArrowsProperty | Identifies the ShowConnectorArrows dependency property. |
ShowConnectorPortsProperty | Identifies the ShowConnectorPorts dependency property. |
ShowNodeCardAccentStripeProperty | Identifies the ShowNodeCardAccentStripe dependency property. |
ShowNodeCardAvatarProperty | Identifies the ShowNodeCardAvatar dependency property. |
ShowNodeCardShadowProperty | Identifies the ShowNodeCardShadow dependency property. |
SpacingBetweenChildNodeToParentProperty | Identifies the SpacingBetweenChildNodeToParent dependency property. |
SpacingBetweenSiblingNodesProperty | Identifies the SpacingBetweenSiblingNodes dependency property. |
TreeLayoutDirectionProperty | Identifies the TreeLayoutDirection dependency property. |
ZoomFactorProperty | Identifies the ZoomFactor dependency property. |
Constructors
OrganizedTree
Creates an empty chart.
Remarks
Nodes starts as an empty list. Add the top-level nodes to it and call
RenderTree to draw them.
Properties
CollapseExpandAnimationDuration
Gets or sets how long the collapse and expand animation lasts.
- Value
- The length in milliseconds; the default is 220. Zero or less turns the animation off.
See also
CollapsedChildCountBrush
Gets or sets the fill of the badge that counts the nodes hidden under a collapsed node.
- Value
- The default is a red,
#DB4C4C. The number is drawn in white.
See also
ConnectingLineBrush
Gets or sets the colour of the connecting lines – and, unless they are given colours of their own, of the ports, arrowheads, chevrons and collapse / expand buttons.
- Value
- The default with no skin in force is a mid grey, which shows on light and dark surfaces; a skin sets its own.
Example
<org:OrganizedTree ConnectingLineBrush="#9AA5B1" ConnectingLineThickness="2" />ConnectingLineStrokeDashArray
Gets or sets the pattern of dashes and gaps the connecting lines are drawn with.
- Value
- Alternating dash and gap lengths, in multiples of
ConnectingLineThickness, as forStrokeDashArray:4 2draws dashes twice as long as their gaps. The default isnull;nullor empty draws solid lines.
Remarks
The chart redraws when a new collection is set, not when the numbers in the current one are changed.
Example
<org:OrganizedTree ConnectingLineStrokeDashArray="3 2" />ConnectingLineStyle
Gets or sets a Style for the connecting lines, for effects the line properties do not
offer.
- Value
- A style whose target type is
Line; the default isnull.
Remarks
Used only while IsUsingCustomLineStyle is true and
ConnectorStyle is ConnectorStyle.Elbow. The style then replaces
ConnectingLineBrush, ConnectingLineThickness and
ConnectingLineStrokeDashArray for the lines, so it should set at least
Stroke and StrokeThickness. Call RenderTree
after setting it.
Example
<org:OrganizedTree IsUsingCustomLineStyle="True">
<org:OrganizedTree.ConnectingLineStyle>
<Style TargetType="Line">
<Setter Property="Stroke" Value="SlateGray" />
<Setter Property="StrokeThickness" Value="2" />
<Setter Property="Opacity" Value="0.7" />
</Style>
</org:OrganizedTree.ConnectingLineStyle>
</org:OrganizedTree>ConnectingLineThickness
Gets or sets the width of the connecting lines.
- Value
- The width in logical pixels (1/96 inch); the default is 3.
Remarks
Arrowheads and, by default, chevrons are sized from it.
ConnectorArrowBrush
Gets or sets the fill of the arrowheads drawn when ShowConnectorArrows is on.
- Value
- The default is
null: the arrowheads takeConnectingLineBrush.
ConnectorChevronBrush
Gets or sets the colour of the direction chevrons.
- Value
- The default is
null: the chevrons takeConnectingLineBrush.
ConnectorChevronSize
Gets or sets the size of each direction chevron, from the tip of one arm to the tip of the other.
- Value
- The size in logical pixels (1/96 inch); the default is 8.
ConnectorChevronThickness
Gets or sets the width of the strokes the direction chevrons are drawn with.
- Value
- The width in logical pixels (1/96 inch). The default, 0, uses
ConnectingLineThicknessbut never less than 1.5, below which a chevron reads as a smudge; set a value to draw them thinner than that on purpose.
ConnectorChevrons
Gets or sets the chevrons drawn part-way along each connector to show which way the relationship runs.
- Value
- The default is
ConnectorChevronStyle.None.
Remarks
One or two chevrons are drawn on each line to a child, pointing towards the child
(ConnectorChevronStyle.Forward) or back towards the parent
(ConnectorChevronStyle.Backward). Their look is set by
ConnectorChevronBrush, ConnectorChevronSize and
ConnectorChevronThickness. They are drawn even while
IsShowConnectingLines is off.
ConnectorCornerRadius
Gets or sets how rounded the corners of ConnectorStyle.RoundedElbow connectors are.
- Value
- The radius in logical pixels (1/96 inch); the default is 10. A corner is made smaller where the lines are too short for it, and a radius below 0.5 gives square corners.
ConnectorPortBrush
Gets or sets the fill of the connector ports.
- Value
- The default is
null: the ports takeConnectingLineBrush.
See also
ConnectorPortSize
Gets or sets the diameter of the connector ports.
- Value
- The diameter in logical pixels (1/96 inch); the default is 9. A negative, infinite or NaN value is taken as 0, which draws no port.
See also
ConnectorPortStrokeBrush
Gets or sets the colour of a ring drawn around each connector port – white, say, to lift the ports off the lines.
- Value
- The default is
null: no ring. The ring isConnectorPortStrokeThicknesswide.
ConnectorPortStrokeThickness
Gets or sets the width of the ring around each connector port.
- Value
- The width in logical pixels (1/96 inch); the default is 0, no ring. It has no effect while
ConnectorPortStrokeBrushisnull.
ConnectorStyle
Gets or sets the shape of the lines joining parents to children.
- Value
- The default is
ConnectorStyle.Elbow: square elbows with one bar across each set of children.
Remarks
ConnectingLineStyle applies only to ConnectorStyle.Elbow. The
other styles draw one path per child and round the line ends;
ConnectorStyle.RoundedElbow takes its corner size from
ConnectorCornerRadius.
Example
<org:OrganizedTree ConnectorStyle="RoundedElbow" ConnectorCornerRadius="12"
ShowConnectorPorts="True" ConnectorChevrons="Forward" />ExpanderButtonBackground
Gets or sets the face colour of the built-in collapse / expand buttons.
- Value
- The default is
null, which draws a white face.
Remarks
The face and the ring change places to show state: a collapsed button, and a button under
the pointer, is filled with ExpanderButtonBorderBrush and its sign drawn in this
brush.
ExpanderButtonBorderBrush
Gets or sets the ring colour of the built-in collapse / expand buttons, which is also the fill of a collapsed button.
- Value
- The default is
null: the buttons takeConnectingLineBrush, so they match the lines.
ExpanderButtonBorderThickness
Gets or sets the width of the ring around the built-in collapse / expand buttons.
- Value
- The width in logical pixels (1/96 inch); the default is 2.
ExpanderButtonGlyphBrush
Gets or sets the colour of the plus and minus signs on the built-in collapse / expand buttons.
- Value
- The default is
null: the signs take the ring colour,ExpanderButtonBorderBrush.
ExpanderButtonSize
Gets or sets the diameter of the collapse / expand buttons.
- Value
- The diameter in logical pixels (1/96 inch); the default is 22. A negative, infinite or NaN value is taken as 0, which leaves the buttons with no size.
See also
ExpanderButtonStyle
Gets or sets a Style for the collapse / expand buttons, replacing the chart's own
round buttons.
- Value
- A style whose target type is
Button; the default isnull, which draws the built-in buttons.
Remarks
The button's content is the text "+" while its branch is collapsed and a minus sign while
it is open, so a style needs only to present that content. Its width and height are always
ExpanderButtonSize, and the tooltip says "Collapse" or "Expand (n hidden)".
With a style of your own, ExpanderButtonBackground,
ExpanderButtonBorderBrush, ExpanderButtonBorderThickness,
ExpanderButtonGlyphBrush and the hidden-node badge are not used.
IsCollapseExpandAnimated
Gets or sets whether nodes fade and grow into view when a branch is expanded, and fade and shrink away when it is collapsed.
- Value
true, the default, to animate;falseto show and hide them at once.
Remarks
The animation lasts CollapseExpandAnimationDuration. Drawing the chart with
RenderTree is never animated.
IsCollapseExpandOfNodesEnabled
Gets or sets whether each parent node has a button that collapses its branch out of sight and expands it again.
- Value
trueto show the collapse / expand buttons and honour each node'sOrganizedTreeNode.IsInCollapsedState; the default isfalse.
Remarks
The button is a small circle where the parent's line meets the bar across its children
(for ConnectorStyle.Elbow), or just beyond the parent's edge for the other
connector styles. It shows a minus sign while the branch is open and a plus sign when it is
folded, with a badge counting the hidden nodes (ShowCollapsedChildCount). The
keyboard does the same to the selected node: Enter or Space toggles it, + expands and – collapses.
The change is animated unless IsCollapseExpandAnimated is off.
To open the chart with branches already folded, set
OrganizedTreeNode.IsInCollapsedState on those nodes before calling
RenderTree. Turning this property off expands every node and sets every node's
OrganizedTreeNode.IsInCollapsedState back to false.
The buttons are drawn by the chart; see ExpanderButtonSize,
ExpanderButtonBackground, ExpanderButtonBorderBrush and
ExpanderButtonStyle to change how they look.
See also
IsMouseWheelZoomEnabled
Gets or sets whether holding Ctrl and turning the mouse wheel zooms the chart in and out around the pointer.
- Value
true, the default, to zoom with the wheel; otherwise,false.
Remarks
The wheel without Ctrl is left alone, so an enclosing scroll viewer still scrolls with it.
See also
IsNodeHoverEffectEnabled
Gets or sets whether a node rises slightly, and a card's shadow deepens, while the pointer is over it.
- Value
true, the default, to animate the node under the pointer; otherwise,false.
Remarks
An element of your own that already has a UIElement.RenderTransform is not
lifted. The highlight of the path to the root is separate: see
IsPathToRootHighlighted.
IsNodeSelectionEnabled
Gets or sets whether the user can select a node by clicking it or with the arrow keys.
- Value
true, the default, to allow selection;falsefor a chart that is only looked at.
Remarks
Turning it off hides the selection ring and stops the keyboard moving the selection or
collapsing nodes. SelectedNode can still be set from code.
See also
IsPathToRootHighlighted
Gets or sets whether the line of command from a node up to the top of the chart is drawn in
PathHighlightBrush.
- Value
true, the default, to highlight the path; otherwise,false.
Remarks
The path followed is the one from the node under the pointer or, when the pointer is over
no node, from SelectedNode. Every connector, port, arrowhead and chevron on the way
up is coloured.
IsShowConnectingLines
Gets or sets whether the lines joining parents to children are drawn.
- Value
true, the default, to draw them;falsefor a chart of cards alone.
Remarks
Turning the lines off leaves everything else in place: the collapse / expand buttons, and any ports, arrowheads and chevrons that are switched on.
IsUsingCustomLineStyle
Gets or sets whether the connecting lines are drawn with ConnectingLineStyle rather
than with the line properties.
- Value
trueto use the style; the default isfalse. It has no effect whileConnectingLineStyleisnull.
Remarks
Applies to ConnectorStyle.Elbow connectors only. Call
RenderTree after changing it.
NodeCardAccentBrush
Gets or sets the colour of the stripe and avatar on the built-in cards whose node has no
OrganizedTreeNode.AccentBrush of its own.
- Value
- The default with no skin in force is a blue,
#3B7DDD.
NodeCardBackground
Gets or sets the fill of the built-in cards.
- Value
- The default with no skin in force is white.
NodeCardBorderBrush
Gets or sets the colour of the thin outline around the built-in cards.
- Value
- The default with no skin in force is a light grey,
#DDE1E7.
NodeCardCornerRadius
Gets or sets how rounded the corners of the built-in cards are.
- Value
- The radius in logical pixels (1/96 inch); the default is 8. It is never more than half the card's height, so the largest value gives cards with fully rounded ends.
NodeCardHeight
Gets or sets the height of the built-in cards.
- Value
- The height in logical pixels (1/96 inch); the default is 58. A value below 24 is drawn as 24.
Remarks
The avatar is sized from it: 18 less than the height, between 16 and 40 across.
NodeCardSubtitleBrush
Gets or sets the colour of the second line of text on the built-in cards.
- Value
- The default with no skin in force is a mid grey,
#6B7280.
NodeCardTitleBrush
Gets or sets the colour of the first, bold line of text on the built-in cards.
- Value
- The default with no skin in force is a near-black,
#1F2937.
Remarks
The title is drawn in the chart's Control.FontFamily, one point larger than
its Control.FontSize, and the subtitle one point smaller.
NodeCardWidth
Gets or sets the width of the built-in cards.
- Value
- The width in logical pixels (1/96 inch); the default is 180. A value below 40 is drawn as 40.
Remarks
Applies to every node drawn as a card, not to nodes with an element of their own. A title or subtitle too long for the card is cut short with an ellipsis.
NodeSelectionBrush
Gets or sets the colour of the ring drawn around the selected node.
- Value
- The default with no skin in force is a blue,
#2F80ED.
Remarks
The ring is drawn just outside the node, following a card's rounded corners, with a soft glow of the same colour.
See also
NodeSelectionThickness
Gets or sets the width of the ring drawn around the selected node.
- Value
- The width in logical pixels (1/96 inch); the default is 2. A negative value is taken as 0.
Nodes
Gets or sets the top-level nodes of the chart – usually one, the head of the organisation; several draw several trees side by side.
- Value
- The list of root nodes, each holding its own
OrganizedTreeNode.Children. A new chart starts with an empty list.
Remarks
A new list, set from code or given through a binding, redraws a chart that is on screen. The
list does not report changes to its contents, so call RenderTree after adding, removing
or changing nodes in it.
Setting it to null gives an empty list.
PathHighlightBrush
Gets or sets the colour of the highlighted path from a node up to its root.
- Value
- The default is an amber,
#F59E0B.
See also
SelectedNode
Gets or sets the node that is selected on the chart, ringed in NodeSelectionBrush.
- Value
- The selected node, or
null(the default) when nothing is selected. Binds two-way by default.
Remarks
A click on a node selects it. With the keyboard focus in the chart, the arrow keys move the selection: towards the root to the parent, away from it to the child nearest the middle (expanding a collapsed node first), and across to the next node on show on the same level. Home selects the first root node, and the first arrow key press with nothing selected does the same.
When a collapse hides the selected node, the selection moves up to the nearest node still on
show. Setting a node that is not on the chart shows no ring. Each change raises
SelectedNodeChanged.
Example
// Select the finance director and scroll to the card.
OrganizedTreeNode finance = orgChart.Nodes[0].Children[0];
orgChart.SelectedNode = finance;
orgChart.CenterOnNode(finance);See also
ShowCollapsedChildCount
Gets or sets whether a collapsed node's button carries a small badge counting the nodes hidden beneath it.
- Value
true, the default, to show the badge;falseto leave it off.
Remarks
The count includes every node in the folded branch, not only the direct children; above
99 it shows "99+". The badge is filled with CollapsedChildCountBrush and is part of the
built-in buttons only, so it does not appear with an ExpanderButtonStyle.
ShowConnectorArrows
Gets or sets whether each connector ends in an arrowhead pointing at the child.
- Value
trueto draw arrowheads; the default isfalse.
Remarks
The arrowheads are four times ConnectingLineThickness long, and never less than
9 logical pixels, filled with ConnectorArrowBrush. With
ShowConnectorPorts on, the tip stops at the edge of the port.
ShowConnectorPorts
Gets or sets whether a small round dot is drawn at each point where a connector meets a card.
- Value
trueto draw the ports; the default isfalse.
Remarks
The ports are ConnectorPortSize across, filled with
ConnectorPortBrush and ringed with ConnectorPortStrokeBrush. They are
drawn even while IsShowConnectingLines is off.
ShowNodeCardAccentStripe
Gets or sets whether the built-in cards carry a stripe of the accent colour down their left edge.
- Value
true, the default, to show the stripe, 5 logical pixels wide; otherwise,false.
ShowNodeCardAvatar
Gets or sets whether the built-in cards show a round avatar with the node's picture or initials.
- Value
true, the default, to show the avatar;falsefor cards of text alone.
See also
ShowNodeCardShadow
Gets or sets whether the built-in cards cast a soft shadow below them.
- Value
true, the default, to draw the shadow; otherwise,false.
Remarks
With IsNodeHoverEffectEnabled on, the shadow deepens under the pointer. A
very large chart draws faster without shadows.
SpacingBetweenChildNodeToParent
Gets or sets the gap between a parent's card and its children's cards – the distance from one level of the chart to the next.
- Value
- The gap in logical pixels (1/96 inch); the default is 24. The bar joining a parent's children runs along the middle of it.
Remarks
A larger gap gives the connectors, arrowheads, chevrons and collapse buttons more room;
48 or more suits ConnectorStyle.Curved connectors.
SpacingBetweenSiblingNodes
Gets or sets the gap between neighbouring cards on the same level, and between one branch and the next.
- Value
- The gap in logical pixels (1/96 inch); the default is 9.
TreeLayoutDirection
Gets or sets which way the chart grows from its root nodes: down, up, to the right or to the left.
- Value
- The direction; the default is
TreeLayoutDirection.TopDown, roots at the top.
Remarks
The cards keep their shape in every direction; only their arrangement turns. In the two
horizontal directions SpacingBetweenChildNodeToParent becomes a horizontal gap and
SpacingBetweenSiblingNodes a vertical one, and the arrow keys turn with the
chart.
Example
<org:OrganizedTree x:Name="orgChart" TreeLayoutDirection="LeftToRight" />ZoomFactor
Gets or sets the scale the chart is drawn at: 1 is actual size, 0.5 half size, 2 double.
- Value
- The scale, from 0.1 to 8; the default is 1. A value outside that range is taken as the nearer limit, and NaN or infinity as 1.
Remarks
The chart takes up its scaled size, so an enclosing ScrollViewer scrolls over
the right area at any zoom. With IsMouseWheelZoomEnabled on, Ctrl and the mouse wheel
change the zoom by 10% a step around the pointer; ZoomToFit chooses the zoom that
shows the whole chart.
Example
<Slider Minimum="0.25" Maximum="2" Value="{Binding ZoomFactor, ElementName=orgChart}" />Methods
CenterOnNode
Scrolls the enclosing ScrollViewer so that a node is in the middle of the visible
area – to show a search result, say.
Parameters
node- The node to bring to the centre. Nothing happens when it is
nullor not on the chart as last drawn.
Remarks
The node is not selected; set SelectedNode as well for that. A node in a collapsed
branch is not on show, so expand the branch first. Without an enclosing scroll viewer the node is
only brought into view.
Example
OrganizedTreeNode match = FindByName(orgChart.Nodes, searchBox.Text);
if (match != null)
{
orgChart.SelectedNode = match;
orgChart.CenterOnNode(match);
}Export
Takes a picture of the whole chart, for saving to a file, pasting into a report or printing in a layout of your own.
Returns
A bitmap of the chart as it is drawn – at the current ZoomFactor, with any
branches collapsed, and including the parts scrolled out of view – at the resolution of the
screen the chart is on, in Pbgra32. Areas the chart does not cover are
transparent.
Remarks
Draw the chart with RenderTree first. The bitmap is the size of the chart.
Example
using System.IO;
using System.Windows.Media.Imaging;
BitmapSource picture = orgChart.Export();
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(picture));
using (FileStream file = File.Create(@"C:\Reports\Organisation.png"))
{
encoder.Save(file);
}See also
OnKeyDown
Moves the selection with the arrow keys and Home, and collapses or expands the selected node with Enter, Space, + and -.
Parameters
e- The key event data. Keys the chart acts on are marked handled.
Remarks
Does nothing while IsNodeSelectionEnabled is off or the chart has no nodes. The
arrow keys follow TreeLayoutDirection; the collapse keys act only while
IsCollapseExpandOfNodesEnabled is on and the node has children. An override should
call the base method to keep this behaviour.
OnMouseWheel
Zooms the chart in or out by 10% around the pointer when Ctrl is held and
IsMouseWheelZoomEnabled is on.
Parameters
e- The wheel event data. It is marked handled only when the chart zooms, so the wheel without Ctrl still scrolls an enclosing scroll viewer.
Shows the print dialog and prints the whole chart, including the parts scrolled out of view, with margins of 84 logical pixels (7/8 inch) all round.
Remarks
The same as Print() with a uniform margin of 84. See that overload for
how the chart is divided into pages.
See also
Shows the print dialog and prints the whole chart, including the parts scrolled out of view, with the margins you choose.
Parameters
marginFactor- The distance from each edge of the paper to the printed chart, in logical pixels (1/96 inch): 96 is an inch, 38 is about a centimetre.
Remarks
The print job is named after the control's FrameworkElement.Name. Nothing is
printed if the user cancels the dialog.
A chart taller than one page is continued on as many pages as it needs, top to bottom,
and a page range chosen in the dialog is honoured. The chart is not divided across the width of
the paper: anything wider than the printable width is cut off. For a wide organisation, print in
landscape, reduce SpacingBetweenSiblingNodes or NodeCardWidth, or use
TreeLayoutDirection.LeftToRight so that the tree grows down the page.
Example
// Half-inch margins.
orgChart.Print(new Thickness(48));RenderTree
Draws the chart from Nodes, laying out every node and drawing the lines, buttons and
selection again.
Remarks
Call it once the nodes are in place, and again after any change to the nodes themselves –
adding or removing a node, changing a node's OrganizedTreeNode.Children,
OrganizedTreeNode.Title, picture or element, or setting
OrganizedTreeNode.IsInCollapsedState from code. The node lists are plain lists and
raise no notifications, so the chart does not redraw on its own when they change. A change to a
property of the chart itself redraws it without this call.
Which branches are collapsed and which node is selected are kept. The built-in cards are made afresh on each call.
Nodes must not be null when this is called; to
empty the chart, clear the list instead.
Example
// A new starter joins the payroll team.
OrganizedTreeNode payroll = orgChart.Nodes[0].Children[0].Children[1];
payroll.Children.Add(new OrganizedTreeNode("Megan Price", "Payroll Assistant"));
orgChart.RenderTree();See also
ZoomToFit
Sets ZoomFactor so that the whole chart fits in the visible area, and scrolls back to
its top-left corner.
Remarks
The area is the viewport of the enclosing ScrollViewer or, without one, the
chart's parent element, less the chart's FrameworkElement.Margin. A chart smaller than
the area is enlarged to fill it, up to 8 times.
Nothing happens before the chart has been drawn and laid out, or while the area has no size;
call it from the window's Loaded event, or later, rather than from its constructor.
Example
Loaded += (sender, e) => orgChart.ZoomToFit();See also
Events
SelectedNodeChanged
Occurs when the selected node changes – by a click, the keyboard, code, or a collapse that hides the selected node.
Remarks
The event data's OldValue and NewValue are the nodes selected before and
after; either can be null. It is a bubbling routed event, so it can be handled on
a parent element too.
Example
orgChart.SelectedNodeChanged += (sender, e) =>
{
statusText.Text = e.NewValue == null
? "No one selected"
: e.NewValue.Title + " - " + e.NewValue.Subtitle;
};See also
Fields
CollapseExpandAnimationDurationProperty static
Identifies the CollapseExpandAnimationDuration dependency property.
CollapsedChildCountBrushProperty static
Identifies the CollapsedChildCountBrush dependency property.
ConnectingLineBrushProperty static
Identifies the ConnectingLineBrush dependency property.
ConnectingLineStrokeDashArrayProperty static
Identifies the ConnectingLineStrokeDashArray dependency property.
ConnectingLineStyleProperty static
Identifies the ConnectingLineStyle dependency property.
ConnectingLineThicknessProperty static
Identifies the ConnectingLineThickness dependency property.
ConnectorArrowBrushProperty static
Identifies the ConnectorArrowBrush dependency property.
ConnectorChevronBrushProperty static
Identifies the ConnectorChevronBrush dependency property.
ConnectorChevronSizeProperty static
Identifies the ConnectorChevronSize dependency property.
ConnectorChevronThicknessProperty static
Identifies the ConnectorChevronThickness dependency property.
ConnectorChevronsProperty static
Identifies the ConnectorChevrons dependency property.
ConnectorCornerRadiusProperty static
Identifies the ConnectorCornerRadius dependency property.
ConnectorPortBrushProperty static
Identifies the ConnectorPortBrush dependency property.
ConnectorPortSizeProperty static
Identifies the ConnectorPortSize dependency property.
ConnectorPortStrokeBrushProperty static
Identifies the ConnectorPortStrokeBrush dependency property.
ConnectorPortStrokeThicknessProperty static
Identifies the ConnectorPortStrokeThickness dependency property.
ConnectorStyleProperty static
Identifies the ConnectorStyle dependency property.
ExpanderButtonBackgroundProperty static
Identifies the ExpanderButtonBackground dependency property.
ExpanderButtonBorderBrushProperty static
Identifies the ExpanderButtonBorderBrush dependency property.
ExpanderButtonBorderThicknessProperty static
Identifies the ExpanderButtonBorderThickness dependency property.
ExpanderButtonGlyphBrushProperty static
Identifies the ExpanderButtonGlyphBrush dependency property.
ExpanderButtonSizeProperty static
Identifies the ExpanderButtonSize dependency property.
ExpanderButtonStyleProperty static
Identifies the ExpanderButtonStyle dependency property.
IsCollapseExpandAnimatedProperty static
Identifies the IsCollapseExpandAnimated dependency property.
IsCollapseExpandOfNodesEnabledProperty static
Identifies the IsCollapseExpandOfNodesEnabled dependency property.
IsMouseWheelZoomEnabledProperty static
Identifies the IsMouseWheelZoomEnabled dependency property.
IsNodeHoverEffectEnabledProperty static
Identifies the IsNodeHoverEffectEnabled dependency property.
IsNodeSelectionEnabledProperty static
Identifies the IsNodeSelectionEnabled dependency property.
IsPathToRootHighlightedProperty static
Identifies the IsPathToRootHighlighted dependency property.
IsShowConnectingLinesProperty static
Identifies the IsShowConnectingLines dependency property.
IsUsingCustomLineStyleProperty static
Identifies the IsUsingCustomLineStyle dependency property.
NodeCardAccentBrushProperty static
Identifies the NodeCardAccentBrush dependency property.
NodeCardBackgroundProperty static
Identifies the NodeCardBackground dependency property.
NodeCardBorderBrushProperty static
Identifies the NodeCardBorderBrush dependency property.
NodeCardCornerRadiusProperty static
Identifies the NodeCardCornerRadius dependency property.
NodeCardHeightProperty static
Identifies the NodeCardHeight dependency property.
NodeCardSubtitleBrushProperty static
Identifies the NodeCardSubtitleBrush dependency property.
NodeCardTitleBrushProperty static
Identifies the NodeCardTitleBrush dependency property.
NodeCardWidthProperty static
Identifies the NodeCardWidth dependency property.
NodeSelectionBrushProperty static
Identifies the NodeSelectionBrush dependency property.
NodeSelectionThicknessProperty static
Identifies the NodeSelectionThickness dependency property.
NodesProperty static
Identifies the Nodes dependency property.
PathHighlightBrushProperty static
Identifies the PathHighlightBrush dependency property.
SelectedNodeChangedEvent static
Identifies the SelectedNodeChanged routed event.
SelectedNodeProperty static
Identifies the SelectedNode dependency property.
ShowCollapsedChildCountProperty static
Identifies the ShowCollapsedChildCount dependency property.
ShowConnectorArrowsProperty static
Identifies the ShowConnectorArrows dependency property.
ShowConnectorPortsProperty static
Identifies the ShowConnectorPorts dependency property.
ShowNodeCardAccentStripeProperty static
Identifies the ShowNodeCardAccentStripe dependency property.
ShowNodeCardAvatarProperty static
Identifies the ShowNodeCardAvatar dependency property.
ShowNodeCardShadowProperty static
Identifies the ShowNodeCardShadow dependency property.
SpacingBetweenChildNodeToParentProperty static
Identifies the SpacingBetweenChildNodeToParent dependency property.
SpacingBetweenSiblingNodesProperty static
Identifies the SpacingBetweenSiblingNodes dependency property.
TreeLayoutDirectionProperty static
Identifies the TreeLayoutDirection dependency property.
ZoomFactorProperty static
Identifies the ZoomFactor dependency property.