Skip to content

Picker ​

A bottom-sheet single-column wheel picker. It supports options, index clamping, and a toolbar.

Spec source: lh-ui-core/specs/picker.json · Golden cases: lh-ui-core/cases/picker.json (8 cases, translated into xUnit tests)

Basic usage ​

Declarative visibility: when Visible is false nothing is rendered; after confirm / cancel Close fires and the host sets Visible back to false accordingly.

9:41Picker basics
CancelSelectConfirm
Option oneOption twoOption three

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

csharp
var picker = new LhPicker
{
    Options = new[] { "Option one", "Option two", "Option three" },
    Value = 1,
    Title = "Select",
};
picker.ValueChange += index => { /* Selected index after the wheel stops */ };
picker.Confirm += index => { /* Currently selected index */ };
picker.Close += () => picker.Visible = false;

picker.Visible = true;

Index clamping ​

When Value is out of range it is clamped into the options range: negatives become 0, and anything above the option count - 1 becomes the last item.

csharp
Assert.Equal(0, LhPickerTokens.ClampIndex(-1, 3));   // Negatives become 0
Assert.Equal(2, LhPickerTokens.ClampIndex(100, 3));  // Overflow becomes the last item

API ​

Props ​

PropDescriptionTypeDefault
ValueChangeFired when the wheel stops and the selected item changesevent Action<int>—
ConfirmFired when the confirm button is tapped, carrying the currently selected indexevent Action<int>—
CancelFired when the cancel button is tappedevent Action—
CloseFired after confirm / cancel; the host sets Visible to false accordinglyevent Action—
VisibleWhether the picker is shown; nothing is rendered when falseboolfalse
OptionsArray of option texts (a single column)string[]?null
ValueSelected index (0-based); clamped into the options range when out of rangeint0
TitleTitle in the middle of the toolbarstring""
ConfirmTextConfirm button textstring"确认"
CancelTextCancel button textstring"取消"

Token Reference ​

TokenUsage
picker.heightPanel height
picker.toolbarHeightTop toolbar height (wheel area height = panel height - toolbar height)
picker.itemHeightOption height (the central indicator spacing is the same)
picker.itemFontSizeOption and toolbar font size
picker.borderRadiusTop corner radius of the panel
color.background.defaultPanel background color
color.background.overlayBackdrop color
color.text.primaryTitle and option color
color.text.secondaryCancel button color
color.primary.defaultConfirm button color
color.border.lighterCentral indicator line color
zIndex.modal / zIndex.modalBackdropPanel / backdrop elevation

Golden Case Reference ​

How the 8 assertions of cases/picker.json map to xUnit tests (tests/LhPickerTests.cs):

case idAssertionLocal test
confirm-emits-onconfirm-with-valueConfirm carries the currently selected indexConfirm_Emits_OnConfirm_With_Value
confirm-also-emits-oncloseConfirm also fires onCloseConfirm_Also_Emits_OnClose
cancel-emits-oncancelCancel fires onCancelCancel_Emits_OnCancel
scroll-emits-onvaluechangeThe wheel stopping fires onValueChangeScroll_Emits_OnValueChange
clamp-negative-value-to-zeroA negative index is clamped to 0Clamp_Negative_Value_To_Zero
clamp-overflow-value-to-lastAn overflowing index is clamped to the last itemClamp_Overflow_Value_To_Last
title-renders-textThe title renders with the font-size tokenTitle_Renders_Text
hidden-not-renderedNothing is rendered when invisibleHidden_Not_Rendered

Plus dark-mode suites: Dark_Colors_Come_From_Dark_Tokens / Dimensions_Are_Identical_In_Dark_Mode. Run: cd lh-ui-windows && dotnet test.

lh-ui native bloodline · Windows (C# + WinUI 3)