PickerWidget
Namespace: Hex1b.Widgets
Assembly: Hex1b.dll
A dropdown picker widget that shows a selected value and opens a list popup when activated. Selection state is owned by the node and preserved across reconciliation.
public sealed record PickerWidget : CompositeWidget<PickerNode>, IEquatable<Hex1bWidget>, IEquatable<CompositeWidget<PickerNode>>, IEquatable<PickerWidget>Inheritance
Object → Hex1bWidget → CompositeWidget<PickerNode> → PickerWidget
Implements
Constructors
PickerWidget(IReadOnlyList<string>)
A dropdown picker widget that shows a selected value and opens a list popup when activated. Selection state is owned by the node and preserved across reconciliation.
Parameters:
Items(IReadOnlyList<String>): The list of items to choose from.
public PickerWidget(IReadOnlyList<string> Items)Properties
InitialSelectedIndex
The initial selected index when the picker is first created. Defaults to 0 (first item).
Returns: Int32
public int InitialSelectedIndex { get; init; }Items
The list of items to choose from.
Returns: IReadOnlyList<String>
public IReadOnlyList<string> Items { get; init; }Methods
BuildContentAsync(PickerNode, ReconcileContext)
Builds the picker's button content with popup behavior.
Parameters:
node(PickerNode):context(ReconcileContext):
Returns: Task<Hex1bWidget>
protected override Task<Hex1bWidget> BuildContentAsync(PickerNode node, ReconcileContext context)OnSelectionChanged(Action<PickerSelectionChangedEventArgs>)
Sets a synchronous handler called when the selection changes.
Parameters:
handler(Action<PickerSelectionChangedEventArgs>):
Returns: PickerWidget
public PickerWidget OnSelectionChanged(Action<PickerSelectionChangedEventArgs> handler)OnSelectionChanged(Func<PickerSelectionChangedEventArgs, Task>)
Sets an asynchronous handler called when the selection changes.
Parameters:
handler(Func<PickerSelectionChangedEventArgs, Task>):
Returns: PickerWidget
public PickerWidget OnSelectionChanged(Func<PickerSelectionChangedEventArgs, Task> handler)UpdateNode(PickerNode)
Updates the node with widget properties before building content.
Parameters:
node(PickerNode):
protected override void UpdateNode(PickerNode node)Remarks
Picker is a composite widget that renders as a button showing the current selection. When clicked (or activated via keyboard), it opens an anchored popup containing a list of all available items. Selecting an item updates the picker and closes the popup.
The selection state () is owned by the node, not the widget. This means the picker maintains its selection across re-renders. Use the OnSelectionChanged method to react to selection changes.
Examples
ctx.Picker(["Apple", "Banana", "Cherry"])
.OnSelectionChanged(e => Console.WriteLine($"Selected: {e.SelectedText}"));