Class OutlinePanel
Shows a document's element tree and keeps its selection in step with an EditorSession.
public class OutlinePanel : ContentControl, INotifyPropertyChanging, IBindingTarget, INotifyPropertyChanged, INotifyFocusChanged, IContainerLayout
- Inheritance
-
OutlinePanel
- Implements
- Inherited Members
- Extension Methods
Remarks
The tree is built from the document's markup, not from the live visuals, so elements whose live copy failed to update still appear (see IsHealthy).
- Document follows the session's selection, and can be set explicitly to show another tracked document.
- Selecting a row selects its element in the session; selecting in the editor frame reveals and selects the row.
- Every document change updates the tree in place, once per layout pass however many edits arrived (and not at all while the panel is hidden): rows are kept per element, so expansion and selection survive edits. Switching to another document starts from fresh rows, so nothing of the previous document is reused; switching back restores which of its elements were expanded.
- While the tree has focus, Ctrl+D runs Duplicate(). Delete is the editor's own binding (Delete).
The panel listens to the session and the document only while it's on a canvas, and catches up when it's added back.
Constructors
OutlinePanel()
Initializes a new instance of the OutlinePanel class.
public OutlinePanel()
Properties
Document
Gets or sets the document the outline shows.
public DesignDocument? Document { get; set; }
Property Value
Remarks
It changes to the selected element's document whenever the session's selection moves to another document.
Roots
Gets the top-level rows: the document's root element, or nothing.
public IReadOnlyList<OutlineItem> Roots { get; }
Property Value
Session
Gets or sets the session whose selection the panel follows and changes, or null.
public EditorSession? Session { get; set; }
Property Value
Tree
Gets the tree the outline is shown in.
public TreeView Tree { get; }
Property Value
Methods
Duplicate()
Inserts a copy of the selected element right after it. Names (x:Name) are left out of the copy, so the
page stays loadable.
public EditResult Duplicate()
Returns
- EditResult
The edit's result; a failure when nothing below the root is selected.
MeasureContent()
Handles custom measure logic when overridden in any UIElement instance.
protected override Size MeasureContent()
Returns
Remarks
This method is called during the measure pass to determine the desired size of the element. The returned size should represent the natural size of the element's content, without considering any constraints, margins, or padding.
When implementing this method:
- Return the natural size needed to display the content;
- Do not include padding, margins, or borders in the returned size;
- Consider the content's actual dimensions (e.g., text length, image size);
- Return Empty if the element has no content.
Move(OutlineItem, OutlineItem, OutlineDropPosition)
Moves item's element next to or into target's element.
public EditResult Move(OutlineItem item, OutlineItem target, OutlineDropPosition position)
Parameters
itemOutlineItemThe row to move.
targetOutlineItemThe row to drop it on.
positionOutlineDropPositionWhere relative to
target.
Returns
- EditResult
The edit's result; a failure for a move into itself, a descendant, or beside the root.
Exceptions
- ArgumentNullException
itemortargetis null.
OnAttached()
Raises the Attached event.
protected override void OnAttached()
Remarks
Propagates Canvas to every element in GetVisualChildren() - this is what makes attaching a whole pre-built subtree (the common pattern: build children, then attach the root once via Add(UIElement)) reach every descendant, not just the immediate root. Each child's own Canvas setter recurses into its children the same way, so this walks the full subtree regardless of depth. Container-specific child-add paths (e.g. OnChildAdded(object?, GenericEventArgs<UIElement>)) still assign Canvas directly for children added after the parent is already attached - this cascade is what covers everything built beforehand.
OnDetached()
Raises the Detached event.
protected override void OnDetached()
Remarks
Propagates null to every element in GetVisualChildren(), mirroring OnAttached() - see its remarks.