Skip to main content

Menu Class

NuGet: GHIElectronics.TinyCLR.UI
Assembly: GHIElectronics.TinyCLR.UI
Namespace: GHIElectronics.TinyCLR.UI.Controls

A simple two-level menu bar: a row of top-level entries; tapping one opens its sub-items as an inline dropdown drawn within the control's bounds. (Embedded UIs have no popup layer, so size the Menu tall enough to show the open dropdown.) Bar entries are sized to their text so they sit close together like a real menu bar. Tapping a sub-item raises ItemClick.

public class Menu : Control

Properties

BarColor

public Color BarColor { get; set; }

Fill of the menu bar.

DropColor

public Color DropColor { get; set; }

Fill of an open dropdown.

ForeColor

public Color ForeColor { get; set; }

Colour of the entry text.

ItemWidth

public int ItemWidth { get; set; }

Minimum width in pixels of the dropdown box. (Top-bar entries auto-size to their text now, so this only sets a floor for how wide an open dropdown is; it grows to fit the widest sub-item.)

DropDirection

public MenuDropDirection DropDirection { get; set; }

Which way dropdowns open. MenuDropDirection.Down (default) suits a menu at the top of the screen; MenuDropDirection.Up suits a menu at the bottom (so the dropdown stays on screen). Up requires the Menu to sit in a Canvas (it shifts its own Canvas.Top up while open so the bar stays put) — same idea WPF handles automatically by re-placing the popup.

Methods

AddItem(MenuEntry item)

public void AddItem(MenuEntry item)

Adds a top-level entry.

MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight)

protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight)

Reports the bar height, growing to include the open dropdown so it is both visible AND hit-testable. When closed the control is only the bar tall, so it doesn't block touches to whatever sits beneath it (hit-testing is bounds-based).

OnTouchUp(TouchEventArgs e)

protected override void OnTouchUp(TouchEventArgs e)

Opens/closes a top entry, or selects a sub-item.

OnRender(DrawingContext dc)

public override void OnRender(DrawingContext dc)

Draws the bar and (if open) the dropdown.

Events

ItemClick

public event MenuItemClickHandler ItemClick

Raised when a sub-item is tapped; the argument is its header text.