Class TextBox
A single-line editable text field. Builds on the existing ITextEvents character synthesizer for typed input and raw IKeyboardInput (only while focused) for caret movement/deletion, and draws its own caret.
public class TextBox : Control, INotifyPropertyChanging, IBindingTarget, INotifyPropertyChanged, INotifyFocusChanged, IContainerLayout
- Inheritance
-
TextBox
- Implements
- Inherited Members
- Extension Methods
Remarks
No text selection (mouse-drag-to-select, Shift+arrow, clipboard cut/copy/paste) in v1 - just single-caret editing. No multi-line/wrapping support either, matching TextBlock.
Constructors
TextBox()
Initializes a new instance of the TextBox class.
public TextBox()
Properties
FontFamily
Gets or sets the font family to render Text with. See FontFamily for how the family is resolved.
public string FontFamily { get; set; }
Property Value
FontSize
Gets or sets the font size, in pixels.
public float FontSize { get; set; }
Property Value
Text
Gets or sets the current text.
[BindingOverride(BindingMode.TwoWay)]
public string Text { get; set; }
Property Value
Methods
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.
OnDetached()
Raises the Detached event.
protected override void OnDetached()
Remarks
Propagates null to every element in GetVisualChildren(), mirroring OnAttached() - see its remarks.
OnNavigate(Vector2)
Invoked by Canvas for a directional navigation press (arrow keys, D-pad, left stick) while this element or one of its descendants has focus.
protected override bool OnNavigate(Vector2 direction)
Parameters
directionVector2The pressed direction: one of the four unit vectors, in UI space (+Y down).
Returns
- bool
true to claim the press. Canvas calls the focused element first, then each ancestor, and stops at the first claim. When nothing claims it, focus moves to the nearest control in
direction(see MoveFocus(Vector2)). The base implementation returns false.
Remarks
Claim only what you use, and let presses go at your edges (a list at its last row, a caret at the end of its text), so focus can move on to the next control.
OnRender(IRenderContext)
Handles custom render logic when overridden in any UIElement instance.
protected override void OnRender(IRenderContext context)
Parameters
contextIRenderContextThe context to render with.
Remarks
When Text is wider than the visible content area, this scrolls horizontally to keep the
caret in view - like a WPF TextBox, never like TextBlock (which has no caret and
simply overflows/clips). Icy.UI.Controls.TextBox.scrollOffset persists across renders and is only nudged when the
caret would otherwise leave a small margin band near either edge, so scrolling doesn't jitter on every
keystroke - it moves exactly as far as needed to bring the caret back into view, the same way typing
past the edge of a real text field does.
Events
TextChanged
Occurs when Text changes.
public event EventHandler? TextChanged