This document captures design and implementation notes for Switch.
For end-user usage and examples, see Switch.
Switch : ContentVisual (single child Content).Space/Enter and left clickLeft/Right to force off/onSwitch : ContentVisual (sealed)Switch() sets Focusable = true.Switch(Visual content) assigns Content.IsOn : bool
Toggled routed event when it changesIsPressed : bool (read-only public)
Toggled (bubble): raised with old/new boolean values.TrackWidth = 4).TrackWidth + SwitchStyle.SpaceBetweenGlyphAndTextwidth = TrackWidth + gap + contentWidthheight = max(1, contentHeight)(TrackWidth, 1).finalRect.Render and is vertically centered within the control’s height.Track rendering:
min(TrackWidth, Bounds.Width) cells for the track.SwitchStyle.TrackLeft/TrackRight for the first/last cell glyphs, spaces otherwise.SwitchStyle.ResolveTrackPart(...):
IsOn and thumb positionThumb rendering:
thumbIndex:
1 (off) or 2 (on)SwitchStyle.ThumbGlyphOn / ThumbGlyphOff over the track.MergeUnspecified)Space / Enter: toggleLeft: set IsOn = falseRight: set IsOn = trueIsPressed = trueIsPressed and toggles IsOn if released within boundsKey knobs:
SpaceBetweenGlyphAndTextTrackLeft / TrackRightThumbGlyphOn / ThumbGlyphOff (defaults match RadioButtonStyle checked/unchecked glyphs; see SwitchStyle.Round preset)TrackOn*, TrackOff* (active/inactive parts)TrackHovered, TrackPressed, TrackFocused, TrackDisabledThumbOn, ThumbOff, ThumbDisabledDefault resolution uses theme colors like Theme.Primary, Theme.Surface, Theme.SurfaceAlt, Theme.Selection, Theme.FocusBorder.
src/XenoAtom.Terminal.UI.Tests/SwitchTests.cs