Class NavigationView
- Namespace
- SharpConsoleUI.Controls
- Assembly
- SharpConsoleUI.dll
A navigation view control with a left navigation pane and a right content area. Inspired by WinUI's NavigationView pattern, encapsulating nav item selection, content switching, and header updates into a single reusable control.
public class NavigationView : BaseControl, IDOMPaintable, INotifyPropertyChanged, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable, IContainer, IContainerControl, IFocusScope
- Inheritance
-
NavigationView
- Implements
- Inherited Members
- Extension Methods
Constructors
NavigationView()
Initializes a new instance of the NavigationView class.
public NavigationView()
Properties
AnimateTransitions
Gets or sets whether width transitions are animated.
public bool AnimateTransitions { get; set; }
Property Value
BackgroundColor
Gets or sets the background color for the container and its child controls.
public Color BackgroundColor { get; set; }
Property Value
CanFocusWithMouse
Whether this control can receive focus via mouse clicks
public bool CanFocusWithMouse { get; }
Property Value
CanReceiveFocus
Whether this control can receive focus
public bool CanReceiveFocus { get; }
Property Value
CompactPaneWidth
Gets or sets the width of the navigation pane in Compact display mode.
public int CompactPaneWidth { get; set; }
Property Value
CompactThreshold
Gets or sets the width threshold at or above which Auto mode resolves to Compact. Below this threshold, Auto resolves to Minimal.
public int CompactThreshold { get; set; }
Property Value
Container
Gets or sets the parent container that hosts this control.
public override IContainer? Container { get; set; }
Property Value
ContentBackgroundColor
Gets or sets the background color for the content panel.
public Color? ContentBackgroundColor { get; set; }
Property Value
ContentBorderColor
Gets or sets the border color for the content panel.
public Color? ContentBorderColor { get; set; }
Property Value
ContentBorderStyle
Gets or sets the border style for the content panel.
public BorderStyle ContentBorderStyle { get; set; }
Property Value
ContentPadding
Gets or sets the padding inside the content panel.
public Padding ContentPadding { get; set; }
Property Value
ContentPanel
Gets the content panel for direct access.
public ScrollablePanelControl ContentPanel { get; }
Property Value
ContentToolbar
Gets the content toolbar control for direct access.
public ToolbarControl ContentToolbar { get; }
Property Value
ContentWidth
Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.
public override int? ContentWidth { get; }
Property Value
- int?
CurrentDisplayMode
Gets the currently resolved display mode (never Auto).
public NavigationViewDisplayMode CurrentDisplayMode { get; }
Property Value
ExpandedThreshold
Gets or sets the width threshold at or above which Auto mode resolves to Expanded.
public int ExpandedThreshold { get; set; }
Property Value
ForegroundColor
Gets or sets the foreground (text) color for the container and its child controls.
public Color ForegroundColor { get; set; }
Property Value
GetConsoleWindowSystem
Gets the console window system instance, or null if not attached to a window system.
public ConsoleWindowSystem? GetConsoleWindowSystem { get; }
Property Value
HasFocus
public bool HasFocus { get; }
Property Value
IsDirty
Gets or sets whether this container needs to be redrawn.
public bool IsDirty { get; set; }
Property Value
IsEnabled
Gets or sets whether this control is enabled and can receive input.
public bool IsEnabled { get; set; }
Property Value
IsPortalOpen
Gets whether the navigation portal overlay is currently open.
public bool IsPortalOpen { get; }
Property Value
ItemForeground
Gets or sets the foreground color for unselected navigation items.
public Color ItemForeground { get; set; }
Property Value
Items
Gets the read-only list of navigation items.
public IReadOnlyList<NavigationItem> Items { get; }
Property Value
NavPaneWidth
Gets or sets the width of the left navigation pane in characters.
public int NavPaneWidth { get; set; }
Property Value
PaneDisplayMode
Gets or sets the pane display mode. When set to Auto, the mode is resolved based on available width and configured thresholds.
public NavigationViewDisplayMode PaneDisplayMode { get; set; }
Property Value
PaneHeader
Gets or sets the markup text shown as the navigation pane header.
public string? PaneHeader { get; set; }
Property Value
SavedFocus
Saved focus position. FocusManager sets this before exiting the scope (if scope opts in). GetInitialFocus should return this when set, then clear it.
public IFocusableControl? SavedFocus { get; set; }
Property Value
Remarks
NavigationView ignores SavedFocus — it always delegates to child panels.
SelectedIndex
Gets or sets the index of the currently selected navigation item.
public int SelectedIndex { get; set; }
Property Value
SelectedItem
Gets the currently selected navigation item, or null if none is selected.
public NavigationItem? SelectedItem { get; }
Property Value
SelectedItemBackground
Gets or sets the background color for the selected navigation item.
public Color SelectedItemBackground { get; set; }
Property Value
SelectedItemForeground
Gets or sets the foreground color for the selected navigation item.
public Color SelectedItemForeground { get; set; }
Property Value
SelectionIndicator
Gets or sets the character used as the selection indicator prefix.
public char SelectionIndicator { get; set; }
Property Value
ShowContentHeader
Gets or sets whether the content header (title + subtitle) is shown.
public bool ShowContentHeader { get; set; }
Property Value
WantsMouseEvents
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; }
Property Value
Methods
AddContentToolbarButton(string, EventHandler<ButtonControl>?)
Adds a button to the content toolbar with an optional click handler.
public ButtonControl AddContentToolbarButton(string text, EventHandler<ButtonControl>? onClick = null)
Parameters
textstringonClickEventHandler<ButtonControl>
Returns
AddContentToolbarItem(IWindowControl)
Adds a control to the content toolbar.
public void AddContentToolbarItem(IWindowControl item)
Parameters
itemIWindowControl
AddContentToolbarSeparator()
Adds a vertical separator to the content toolbar.
public void AddContentToolbarSeparator()
AddHeader(string, Color?)
Adds a header item that groups subsequent child items.
public NavigationItem AddHeader(string text, Color? color = null)
Parameters
Returns
- NavigationItem
The created header NavigationItem.
AddItem(NavigationItem)
Adds a navigation item to the control.
public void AddItem(NavigationItem item)
Parameters
itemNavigationItem
AddItem(string, string?, string?)
Adds a navigation item with the specified properties.
public NavigationItem AddItem(string text, string? icon = null, string? subtitle = null)
Parameters
Returns
- NavigationItem
The created NavigationItem.
AddItemToHeader(NavigationItem, string, string?, string?)
Adds a child item under the specified header. The item is inserted after the header's last existing child.
public NavigationItem AddItemToHeader(NavigationItem header, string text, string? icon = null, string? subtitle = null)
Parameters
headerNavigationItemtextstringiconstringsubtitlestring
Returns
- NavigationItem
The created child NavigationItem.
ClearContentToolbar()
Clears all items from the content toolbar.
public void ClearContentToolbar()
ClearItems()
Removes all navigation items.
public void ClearItems()
GetChildren()
Gets the direct child controls of this container. Does not recursively include grandchildren - recursion happens in caller.
public IReadOnlyList<IWindowControl> GetChildren()
Returns
- IReadOnlyList<IWindowControl>
Read-only list of direct child controls (may include other containers)
Remarks
IMPORTANT: For HorizontalGridControl, this should return columns AND splitters in order: [Column1, Splitter1, Column2, Splitter2, Column3]
Splitters are IInteractiveControl and should be included in Tab navigation.
GetInitialFocus(bool)
Returns the first child to focus when Tab enters this scope. backward=true means Shift+Tab entered from the right — return last child.
public IFocusableControl? GetInitialFocus(bool backward)
Parameters
backwardbool
Returns
GetLogicalContentSize()
Gets the logical size of the control's content without rendering.
public override Size GetLogicalContentSize()
Returns
- Size
The size representing the content's natural dimensions.
GetNextFocus(IFocusableControl, bool)
Returns the next child to focus after Tab from 'current'. Returns null when Tab should exit this scope.
public IFocusableControl? GetNextFocus(IFocusableControl current, bool backward)
Parameters
currentIFocusableControlbackwardbool
Returns
GetVisibleHeightForControl(IWindowControl)
Gets the actual visible height for a control within the container viewport. Returns null if the control is not found or visibility cannot be determined.
public int? GetVisibleHeightForControl(IWindowControl control)
Parameters
controlIWindowControlThe control to check
Returns
- int?
The number of visible lines, or null if unknown
InsertItem(int, NavigationItem)
Inserts a navigation item at the specified index.
public void InsertItem(int index, NavigationItem item)
Parameters
indexintitemNavigationItem
Invalidate(bool, IWindowControl?)
Marks this container as needing to be redrawn.
public void Invalidate(bool redrawAll, IWindowControl? callerControl = null)
Parameters
redrawAllboolIf true, forces a complete redraw of all content.
callerControlIWindowControlThe control that triggered the invalidation, if any.
MeasureDOM(LayoutConstraints)
Measures the control's desired size given the available constraints.
public override LayoutSize MeasureDOM(LayoutConstraints constraints)
Parameters
constraintsLayoutConstraintsThe layout constraints (min/max width/height).
Returns
- LayoutSize
The desired size of the control.
OnDisposing()
Called during Dispose() before Container is set to null.
Override to perform control-specific cleanup (null events, close portals, clear data, etc.).
protected override void OnDisposing()
PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)
Paints the control's content directly to a CharacterBuffer.
public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)
Parameters
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultFgColordefaultBgColor
ProcessKey(ConsoleKeyInfo)
Processes a keyboard input event.
public bool ProcessKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfoThe key information for the pressed key.
Returns
- bool
True if the key was handled by this control; otherwise, false.
ProcessMouseEvent(MouseEventArgs)
Processes a mouse event for this control
public bool ProcessMouseEvent(MouseEventArgs args)
Parameters
argsMouseEventArgsMouse event arguments with control-relative coordinates
Returns
- bool
True if the event was handled and should not propagate further
RemoveContentToolbarItem(IWindowControl)
Removes an item from the content toolbar.
public void RemoveContentToolbarItem(IWindowControl item)
Parameters
itemIWindowControl
RemoveItem(NavigationItem)
Removes the specified navigation item.
public void RemoveItem(NavigationItem item)
Parameters
itemNavigationItem
RemoveItem(int)
Removes the navigation item at the specified index. If the item is a header, its children are also removed.
public void RemoveItem(int index)
Parameters
indexint
SetItemContent(NavigationItem, Action<ScrollablePanelControl>)
Registers a content factory delegate for a navigation item. The delegate is called to populate the content panel when the item is selected.
public void SetItemContent(NavigationItem item, Action<ScrollablePanelControl> populate)
Parameters
itemNavigationItempopulateAction<ScrollablePanelControl>
SetItemContent(int, Action<ScrollablePanelControl>)
Registers a content factory delegate for the navigation item at the specified index.
public void SetItemContent(int index, Action<ScrollablePanelControl> populate)
Parameters
indexintpopulateAction<ScrollablePanelControl>
ToggleHeaderExpanded(NavigationItem)
Toggles the expanded state of a header item, showing or hiding its children.
public void ToggleHeaderExpanded(NavigationItem header)
Parameters
headerNavigationItem
Events
DisplayModeChanged
Raised when the resolved display mode changes.
public event EventHandler<NavigationViewDisplayMode>? DisplayModeChanged
Event Type
ItemInvoked
Raised when the selected item is invoked (Enter/Space key or double-click on already-selected item).
public event EventHandler<NavigationItemChangedEventArgs>? ItemInvoked
Event Type
MouseClick
Event fired when the control is clicked
public event EventHandler<MouseEventArgs>? MouseClick
Event Type
MouseDoubleClick
Event fired when the control is double-clicked
public event EventHandler<MouseEventArgs>? MouseDoubleClick
Event Type
MouseEnter
Event fired when the mouse enters the control area
public event EventHandler<MouseEventArgs>? MouseEnter
Event Type
MouseLeave
Event fired when the mouse leaves the control area
public event EventHandler<MouseEventArgs>? MouseLeave
Event Type
MouseMove
Event fired when the mouse moves over the control
public event EventHandler<MouseEventArgs>? MouseMove
Event Type
MouseRightClick
Event fired when the control is right-clicked (Button3)
public event EventHandler<MouseEventArgs>? MouseRightClick
Event Type
SelectedItemChanged
Raised after the selected item has changed.
public event EventHandler<NavigationItemChangedEventArgs>? SelectedItemChanged
Event Type
SelectedItemChanging
Raised before the selected item changes. Can be canceled.
public event EventHandler<NavigationItemChangingEventArgs>? SelectedItemChanging