ColorPicker
- Assembly:
Fluence.Wpf - Namespace:
Fluence.Wpf.Controls
public class ColorPicker : Control
A control that lets the user pick a color from a saturation/value spectrum, a hue slider, an optional alpha slider, a current/previous preview swatch row, and a text-entry area with an RGB/HSV representation selector, per-channel inputs, an alpha percentage input, and a hex input, mirroring the WinUI 3 ColorPicker. The picker keeps hue, saturation, value, and alpha as its internal source of truth so dragging across the grey axis does not accumulate RGB round-trip drift, the same approach WinUI uses.
Remarks: Scope notes: WinUI's ColorSpectrumShape (the Ring spectrum), the ColorSpectrumComponents permutations, Orientation, and the Min/Max channel range properties are deliberately omitted. The spectrum is fixed to saturation on the x axis by value on the y axis at the selected hue, with hue on a horizontal slider serving as the third-dimension color slider. Channel and alpha text inputs commit live on every valid keystroke like WinUI; the hex input commits on Enter or focus loss, a deliberate deviation from WinUI's live hex commit.
Base type: Control (including inherited WPF and .NET members)
Constructors
ColorPicker
public ColorPicker()
Creates a new ColorPicker instance.
Properties
Color
public Color Color { get; set; }
Gets or sets the currently selected color. Defaults to opaque red. Changing this property raises ColorChanged; values assigned from outside the picker re-derive the internal hue/saturation/value model.
IsAlphaEnabled
public bool IsAlphaEnabled { get; set; }
Gets or sets a value indicating whether the alpha channel can be edited. When false (the default) the alpha slider row and the alpha text input collapse, the hex input parses and displays six digits, and turning the property off pins the picker's alpha back to 255. Programmatic Color assignments keep whatever alpha they carry.
IsAlphaSliderVisible
public bool IsAlphaSliderVisible { get; set; }
Gets or sets a value indicating whether the alpha slider is shown. The slider renders only when both this property and IsAlphaEnabled are true, matching WinUI.
IsAlphaTextInputVisible
public bool IsAlphaTextInputVisible { get; set; }
Gets or sets a value indicating whether the alpha percentage text input is shown. The input renders only when both this property and IsAlphaEnabled are true, matching WinUI.
IsColorChannelTextInputVisible
public bool IsColorChannelTextInputVisible { get; set; }
Gets or sets a value indicating whether the RGB/HSV representation selector and the per-channel text inputs are shown. The hex input is governed separately by IsHexInputVisible and the alpha input by IsAlphaTextInputVisible, matching WinUI. Channel input commits live on every valid keystroke; Enter or focus loss normalizes the text and restores it after invalid input.
IsColorPreviewVisible
public bool IsColorPreviewVisible { get; set; }
Gets or sets a value indicating whether the current/previous preview swatch row is shown.
IsColorSliderVisible
public bool IsColorSliderVisible { get; set; }
Gets or sets a value indicating whether the third-dimension color slider is shown. With the spectrum fixed to saturation by value, the third dimension is the hue slider, matching how WinUI assigns its color slider for that spectrum component pairing.
IsColorSpectrumVisible
public bool IsColorSpectrumVisible { get; set; }
Gets or sets a value indicating whether the saturation/value spectrum square is shown. The hue and alpha sliders remain available when it is hidden.
IsHexInputVisible
public bool IsHexInputVisible { get; set; }
Gets or sets a value indicating whether the hex text input is shown. The input accepts #RRGGBB and #AARRGGBB (the leading # is optional) and commits on Enter or when keyboard focus leaves the box.
IsMoreButtonVisible
public bool IsMoreButtonVisible { get; set; }
Gets or sets a value indicating whether the text-entry area collapses behind a More/Less toggle button. When false (the default) the text inputs are always visible and no toggle is shown; when true the toggle appears and the text-entry area stays collapsed until it is checked, matching WinUI.
PreviousColor
public Color? PreviousColor { get; set; }
Gets or sets the comparison color shown next to the current color in the preview swatch row, or null to hide the comparison swatch.
Methods
OnApplyTemplate
public override void OnApplyTemplate()
Documentation inherited from the Control API.
OnCreateAutomationPeer
protected override AutomationPeer OnCreateAutomationPeer()
Documentation inherited from the Control API.
OnKeyDown
protected override void OnKeyDown(KeyEventArgs e)
Handles arrow and page key presses when keyboard focus is on the spectrum area, adjusting saturation (Left/Right) or value (Up/Down/PageUp/PageDown) and routing through the HSV funnel so there is no RGB round-trip drift.
Parameter e: The key event arguments.
Events
ColorChanged
public event EventHandler<ColorPickerColorChangedEventArgs>? ColorChanged
Occurs after Color changes, whether through the spectrum, the sliders, the channel or hex text inputs, or a programmatic update. Channel and alpha text inputs commit live, so the event can fire once per keystroke while the user types (for example "1", "12", "120"), matching WinUI.
Dependency property identifiers
Use these identifiers with WPF property APIs. The matching CLR properties appear above when the control exposes them.
ColorProperty
public static readonly DependencyProperty ColorProperty
Identifies the Color dependency property.
IsAlphaEnabledProperty
public static readonly DependencyProperty IsAlphaEnabledProperty
Identifies the IsAlphaEnabled dependency property.
IsAlphaSliderVisibleProperty
public static readonly DependencyProperty IsAlphaSliderVisibleProperty
Identifies the IsAlphaSliderVisible dependency property.
IsAlphaTextInputVisibleProperty
public static readonly DependencyProperty IsAlphaTextInputVisibleProperty
Identifies the IsAlphaTextInputVisible dependency property.
IsColorChannelTextInputVisibleProperty
public static readonly DependencyProperty IsColorChannelTextInputVisibleProperty
Identifies the IsColorChannelTextInputVisible dependency property.
IsColorPreviewVisibleProperty
public static readonly DependencyProperty IsColorPreviewVisibleProperty
Identifies the IsColorPreviewVisible dependency property.
IsColorSliderVisibleProperty
public static readonly DependencyProperty IsColorSliderVisibleProperty
Identifies the IsColorSliderVisible dependency property.
IsColorSpectrumVisibleProperty
public static readonly DependencyProperty IsColorSpectrumVisibleProperty
Identifies the IsColorSpectrumVisible dependency property.
IsHexInputVisibleProperty
public static readonly DependencyProperty IsHexInputVisibleProperty
Identifies the IsHexInputVisible dependency property.
IsMoreButtonVisibleProperty
public static readonly DependencyProperty IsMoreButtonVisibleProperty
Identifies the IsMoreButtonVisible dependency property.
PreviousColorProperty
public static readonly DependencyProperty PreviousColorProperty
Identifies the PreviousColor dependency property.