Class UIElement
- Namespace
- PluginUI
- Assembly
- PluginUI.dll
Base class of everything in the visual tree: layout (measure/arrange), rendering, hit testing and input.
public abstract class UIElement
- Inheritance
-
UIElement
- Derived
- Inherited Members
Remarks
Coordinates. Bounds are absolute DIPs in host space after layout: rendering and hit testing need no coordinate transforms.
Layout. WPF-like two-pass layout: Measure(Size) computes DesiredSize from MeasureOverride(Size), Arrange(Rect) assigns Bounds and calls ArrangeOverride(Rect). Explicit Width/Height, min/max sizes, Margin and alignments are applied by the base class.
Extending. Override OnRender(DrawingContext) to draw, MeasureOverride(Size) to report a
natural size, and the On… input methods to react to the mouse and keyboard.
Threading. UI thread only. Use Post(Action) to marshal work from other threads.
Properties
AllowFileDrop
Accepts files dropped from the shell (raises OnFilesDropped(FilesDroppedEventArgs)).
public bool AllowFileDrop { get; set; }
Property Value
Bounds
Arranged rectangle in host DIPs, margins excluded.
[Browsable(false)]
public Rect Bounds { get; }
Property Value
ClipToBounds
Clips children to Bounds.
public bool ClipToBounds { get; set; }
Property Value
Column
Column inside a Grid.
public int Column { get; set; }
Property Value
ColumnSpan
Columns spanned inside a Grid.
public int ColumnSpan { get; set; }
Property Value
ContextMenu
Context menu shown on right click (unless the click is handled).
[Browsable(false)]
public IList<MenuItem>? ContextMenu { get; set; }
Property Value
Cursor
Cursor over this element (Default inherits).
public StandardCursor Cursor { get; set; }
Property Value
DesiredSize
Size requested by the last Measure(Size), margins included.
[Browsable(false)]
public Size DesiredSize { get; }
Property Value
Dock
Docking side inside a DockPanel.
public Side Dock { get; set; }
Property Value
Focusable
Can receive keyboard focus.
public bool Focusable { get; set; }
Property Value
Height
Explicit height in DIPs (NaN = automatic).
public float Height { get; set; }
Property Value
HorizontalAlignment
Horizontal placement in the layout slot.
public HorizontalAlignment HorizontalAlignment { get; set; }
Property Value
Host
Host this element is attached to (null when detached).
[Browsable(false)]
public UIHost? Host { get; }
Property Value
IsEffectivelyEnabled
true if this element and all its ancestors are enabled.
public bool IsEffectivelyEnabled { get; }
Property Value
IsEnabled
Accepts input when true; drawn dimmed otherwise.
public bool IsEnabled { get; set; }
Property Value
IsFocused
true if this element has keyboard focus.
public bool IsFocused { get; }
Property Value
IsHitTestVisible
Participates in hit testing when true.
public bool IsHitTestVisible { get; set; }
Property Value
IsMouseCaptured
true if this element holds the mouse capture.
public bool IsMouseCaptured { get; }
Property Value
IsMouseOver
true while the mouse is over this element or one of its descendants.
[Browsable(false)]
public bool IsMouseOver { get; }
Property Value
IsVisible
Visible and taking layout space when true; collapsed otherwise.
public bool IsVisible { get; set; }
Property Value
Left
X position inside a Canvas.
public float Left { get; set; }
Property Value
Margin
Outer spacing.
public Thickness Margin { get; set; }
Property Value
MaxHeight
Maximum height.
public float MaxHeight { get; set; }
Property Value
MaxWidth
Maximum width.
public float MaxWidth { get; set; }
Property Value
MinHeight
Minimum height.
public float MinHeight { get; set; }
Property Value
MinWidth
Minimum width.
public float MinWidth { get; set; }
Property Value
Name
Optional name (used by the live editor, FindByName(string) and as field name by PluginUIEditor).
public string? Name { get; set; }
Property Value
Opacity
Opacity multiplier (0..1) applied to the element and its children.
public float Opacity { get; set; }
Property Value
Parent
Parent element (null for the root and popups).
[Browsable(false)]
public UIElement? Parent { get; }
Property Value
Row
Row inside a Grid.
public int Row { get; set; }
Property Value
RowSpan
Rows spanned inside a Grid.
public int RowSpan { get; set; }
Property Value
Strings
Texts of the user interface language in effect (Strings), or those of DefaultLanguage while the element is not attached to a host.
protected UIStrings Strings { get; }
Property Value
Tag
Free user data.
[Browsable(false)]
public object? Tag { get; set; }
Property Value
TextMeasurer
Text measurement (device-accurate when attached, approximate otherwise).
public ITextMeasurer TextMeasurer { get; }
Property Value
Theme
Theme in effect (host theme, or the default dark theme when detached).
public Theme Theme { get; }
Property Value
ToolTip
Tooltip text shown after hovering.
public string? ToolTip { get; set; }
Property Value
Top
Y position inside a Canvas.
public float Top { get; set; }
Property Value
UseOpacityLayer
Applies Opacity through an offscreen layer: the element and its children are drawn opaque, then blended as one image, so overlapping children do not show through each other. Costs a layer per frame; by default opacity is a cheaper global alpha (as in VSTGUI). Children of a LayeredPanel use layers automatically (CompositeLayers).
public bool UseOpacityLayer { get; set; }
Property Value
VerticalAlignment
Vertical placement in the layout slot.
public VerticalAlignment VerticalAlignment { get; set; }
Property Value
VisualChildren
Child elements in drawing order (back to front).
public virtual IReadOnlyList<UIElement> VisualChildren { get; }
Property Value
Width
Explicit width in DIPs (NaN = automatic).
public float Width { get; set; }
Property Value
Methods
Arrange(Rect)
Assigns the final layout slot (margins included) and arranges children.
public void Arrange(Rect slot)
Parameters
slotRect
ArrangeOverride(Rect)
Arranges children inside the final bounds.
protected virtual void ArrangeOverride(Rect bounds)
Parameters
boundsRect
CaptureMouse()
Captures the mouse: move/up events go to this element until released.
public void CaptureMouse()
DescendantsAndSelf()
Enumerates this element and all descendants (depth first).
public IEnumerable<UIElement> DescendantsAndSelf()
Returns
FindByName(string)
Finds a descendant (or this element) by Name.
public UIElement? FindByName(string name)
Parameters
namestring
Returns
Focus()
Gives keyboard focus to this element.
public bool Focus()
Returns
GetToolTipText()
Tooltip actually shown: ToolTip by default. Override to supply a computed or localized text (for example from Strings) when ToolTip is not set.
protected virtual string? GetToolTipText()
Returns
- string
The text to show, or
null/ empty for no tooltip.
HitTest(Point)
Returns true if the point hits this element (children excluded). Default: inside Bounds.
public virtual bool HitTest(Point point)
Parameters
pointPoint
Returns
HitTestTree(Point)
Deepest visible, enabled, hit-testable element under the point.
public UIElement? HitTestTree(Point point)
Parameters
pointPoint
Returns
InvalidateMeasure()
Requests a new layout pass.
public void InvalidateMeasure()
InvalidateVisual()
Requests a repaint.
public void InvalidateVisual()
IsAncestorOf(UIElement?)
true if element is this element or one of its descendants.
public bool IsAncestorOf(UIElement? element)
Parameters
elementUIElement
Returns
Measure(Size)
Computes DesiredSize for the given available size (margins included).
public void Measure(Size available)
Parameters
availableSize
MeasureOverride(Size)
Natural size of the content for the available size (margins excluded).
protected virtual Size MeasureOverride(Size available)
Parameters
availableSize
Returns
OnAttached()
Called when the element joins a host (subscribe to external events here).
protected virtual void OnAttached()
OnCaptureLost()
The mouse capture was lost without a button release.
protected virtual void OnCaptureLost()
OnDetached()
Called when the element leaves its host (unsubscribe here).
protected virtual void OnDetached()
OnDragLeave()
Internal drag left this element.
protected virtual void OnDragLeave()
OnDragOver(DragEventArgs)
Internal drag over this element: set Accept to accept.
protected virtual void OnDragOver(DragEventArgs e)
Parameters
OnDrop(DragEventArgs)
Internal drop on this element.
protected virtual void OnDrop(DragEventArgs e)
Parameters
OnFilesDropped(FilesDroppedEventArgs)
Files dropped from the shell (requires AllowFileDrop on this element or an ancestor).
protected virtual void OnFilesDropped(FilesDroppedEventArgs e)
Parameters
OnGotFocus()
Received keyboard focus.
protected virtual void OnGotFocus()
OnKeyDown(KeyEventArgs)
Key pressed while focused (bubbles to parents).
protected virtual void OnKeyDown(KeyEventArgs e)
Parameters
OnKeyUp(KeyEventArgs)
Key released while focused.
protected virtual void OnKeyUp(KeyEventArgs e)
Parameters
OnLostFocus()
Lost keyboard focus.
protected virtual void OnLostFocus()
OnMouseDown(MouseEventArgs)
Mouse button pressed over the element (or captured).
protected virtual void OnMouseDown(MouseEventArgs e)
Parameters
OnMouseEnter()
The mouse entered the element.
protected virtual void OnMouseEnter()
OnMouseLeave()
The mouse left the element.
protected virtual void OnMouseLeave()
OnMouseMove(MouseEventArgs)
Mouse moved over the element (or captured).
protected virtual void OnMouseMove(MouseEventArgs e)
Parameters
OnMouseUp(MouseEventArgs)
Mouse button released.
protected virtual void OnMouseUp(MouseEventArgs e)
Parameters
OnMouseWheel(MouseEventArgs)
Mouse wheel over the element.
protected virtual void OnMouseWheel(MouseEventArgs e)
Parameters
OnRender(DrawingContext)
Draws the element (below its children).
protected virtual void OnRender(DrawingContext dc)
Parameters
OnRenderOverlay(DrawingContext)
Draws above the children (focus rings, overlays...).
protected virtual void OnRenderOverlay(DrawingContext dc)
Parameters
OnTextInput(TextInputEventArgs)
Character typed while focused.
protected virtual void OnTextInput(TextInputEventArgs e)
Parameters
OnVisibilityChanged()
Called when IsVisible changes.
protected virtual void OnVisibilityChanged()
ReleaseMouseCapture()
Releases the mouse capture held by this element.
public void ReleaseMouseCapture()
SetBounds(float, float, float, float)
Positions and sizes the element (absolute layout inside a Canvas).
public void SetBounds(float x, float y, float width, float height)
Parameters
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
Events
KeyDown
Raised on key press.
public event Action<UIElement, KeyEventArgs>? KeyDown
Event Type
MouseDown
Raised on mouse button press (after OnMouseDown(MouseEventArgs)).
public event Action<UIElement, MouseEventArgs>? MouseDown
Event Type
MouseMove
Raised on mouse move.
public event Action<UIElement, MouseEventArgs>? MouseMove
Event Type
MouseUp
Raised on mouse button release.
public event Action<UIElement, MouseEventArgs>? MouseUp
Event Type
MouseWheel
Raised on mouse wheel.
public event Action<UIElement, MouseEventArgs>? MouseWheel