Carousel
Touch/pointer drag page turning (dual thresholds: distance / velocity), autoplay (paused while hovering or dragging), loop wrap-around with boundary clamping, dot indicators, and desktop arrows.
Spec source:
lh-ui-core/specs/carousel.json· Golden cases:lh-ui-core/cases/carousel.json(10 cases, translated into xUnit tests)
Platform notes
The page-index math (normalizePageIndex / nextPageIndex / resolveSwipeTarget / stepAutoplay) is the cross-platform pure-function source in LhCarouselTokens; the control only does gesture sampling and drawing. Page content is supplied through the Pages collection (equivalent to the web side's default-slot direct children); the height defaults to the carousel.height.base token, and assigning Height directly overrides it.
Basic usage
Renders pages and indicator dots according to the element count of the Pages collection; the arrow keys ←/→ turn pages (on focusable targets).
HTML mock preview (Windows / WinUI 3 appearance), not an on-device render
var carousel = new LhCarousel();
carousel.Pages.Add(new Border { /* Page 1 */ });
carousel.Pages.Add(new Border { /* Page 2 */ });
carousel.Pages.Add(new Border { /* Page 3 */ });
carousel.LhOnChange += index => { /* Current page index (0-based) */ };Indicator and autoplay
Indicator (dots / none) + IndicatorPosition (bottom in the normal flow / overlay overlaid on the content); Autoplay is the autoplay interval in ms (0 = off), paused while hovering and dragging.
HTML mock preview (Windows / WinUI 3 appearance), not an on-device render
new LhCarousel
{
Autoplay = 3000,
Indicator = LhCarouselIndicator.Dots,
IndicatorPosition = LhCarouselIndicatorPosition.Overlay,
};Loop and boundaries
Loop (default true) wraps; with false, boundaries clamp (next/prev do not switch, and autoplay self-stops at the last page). Drag page turning uses dual thresholds: the distance exceeds 20% of the page width, or the speed exceeds 0.5px/ms; swiping left goes to the next page, swiping right goes to the previous page. ShowArrow shows left/right arrows (desktop); Disabled stops autoplay and gestures.
HTML mock preview (Windows / WinUI 3 appearance), not an on-device render
var carousel = new LhCarousel { Loop = false, ShowArrow = true };
carousel.Next(); // Next page (does not switch at the last page when non-loop)
carousel.Prev(); // Previous page (at the first page, loop wraps to the last page)
carousel.GoTo(2); // Jump to the given page (negative and out-of-range values are normalized per loop semantics)API
Props
| Prop | Description | Type | Default |
|---|---|---|---|
Value | Current page index (controlled; without it the component runs itself) | int? | null |
Autoplay | Autoplay interval in ms (0 = off); paused while hovering and dragging | int | 0 |
Loop | Loop wrap-around; with false, boundaries clamp | bool | true |
Indicator | Indicator form | LhCarouselIndicator | Dots |
IndicatorPosition | Indicator position | LhCarouselIndicatorPosition | Bottom |
Height | Height in epx (a native FrameworkElement property; defaults to the carousel.height.base token) | double | 200 |
ShowArrow | Show left/right arrows (desktop) | bool | false |
Disabled | Disabled: grays out and stops autoplay and gestures | bool | false |
AriaLabel | Accessibility name (falls back to the page-number announcement when unset) | string? | null |
LhCarouselIndicator
| Value | Description |
|---|---|
Dots | Dot indicator (the active dot scales up per carousel.indicator.dotActiveScale) |
None | No indicator shown |
LhCarouselIndicatorPosition
| Value | Description |
|---|---|
Bottom | Last row of the normal flow |
Overlay | Overlaid on the content, offset from the bottom by carousel.indicator.overlayBottom |
Events
| Event | Payload | Description |
|---|---|---|
LhOnChange | int value | Page change (covers both uncontrolled self-advance and controlled write-back) |
Methods
| Method | Description |
|---|---|
Prev() | Previous page (loop wraps; non-loop stops at the first page; no effect when disabled) |
Next() | Next page (loop wraps; non-loop does not switch at the last page; no effect when disabled) |
GoTo(int) | Jump to the given page (negative and out-of-range values are normalized per loop semantics; no effect when disabled) |
Token Reference
| Token | Usage |
|---|---|
carousel.height.base | Default height |
carousel.indicator.dotSize | Dot diameter |
carousel.indicator.dotGap | Dot spacing |
carousel.indicator.dotActiveScale | Active dot scale-up increment |
carousel.indicator.overlayBottom | Bottom spacing in overlay form |
color.primary.default | Active dot color |
color.text.disabled | Inactive dot color |
color.background.default | Carousel background color |
Golden Case Reference
How the 10 assertions of cases/carousel.json map to xUnit tests (tests/LhCarouselTests.cs):
| case id | Assertion | Local test |
|---|---|---|
renders-pages-and-dots | Renders pages and indicator dots according to the content page count | Indicator_Tokens_Applied (token fallback; page and dot counts are manually walked through in the docs app) |
next-emits-change | next turns to the next page and fires the callback (value=1) | Next_Emits_Change |
nonloop-stops-at-last | With non-loop, next at the last page does not switch | NonLoop_Stops_At_Last |
loop-wraps-negative | With loop, prev at the first page wraps to the last page (value=2) | Loop_Wraps_Negative |
drag-over-threshold-flips | Drag distance over the threshold (20% of the page width) turns the page | Drag_Over_Threshold_Flips |
flick-velocity-flips | A fast flick (speed over the threshold) turns the page even when the distance falls short | Flick_Velocity_Flips |
small-drag-keeps-page | Insufficient distance and slow speed keep the current page | Small_Drag_Keeps_Page |
autoplay-stops-at-last-nonloop | Autoplay self-stops at the last page (non-loop) | Autoplay_Stops_At_Last_NonLoop |
disabled-blocks-gesture | In the disabled state, gestures do not turn the page (color.text.disabled applied) | Disabled_Blocks_Gesture |
aria-region-announcement | role=region + carousel announcement + page number | Aria_Announcement_Notes (the accessibility tree is manually walked through in the docs app) |
Plus supplementary assertions: Right_Swipe_Goes_To_Prev_Page / Autoplay_Loops_Wraps_Around plus the dark-mode suites Dark_Colors_Come_From_Dark_Tokens / Dimensions_Are_Identical_In_Dark_Mode. Run: cd lh-ui-windows && dotnet test.

