Skip to content

feat: Add SelectorBar control#1741

Open
A-Words wants to merge 7 commits into
lepoco:mainfrom
A-Words:feature/selector-bar
Open

feat: Add SelectorBar control#1741
A-Words wants to merge 7 commits into
lepoco:mainfrom
A-Words:feature/selector-bar

Conversation

@A-Words

@A-Words A-Words commented Jul 7, 2026

Copy link
Copy Markdown

Pull request type

Please check the type of change your PR introduces:

  • Update
  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes

What is the current behavior?

WPF UI does not provide a SelectorBar control for switching between a small number of views.

Issue Number: #1317

What is the new behavior?

  • Adds SelectorBar and SelectorBarItem, styled after the WinUI 3 SelectorBar.
  • Supports single selection, horizontal scrolling, keyboard navigation, right-to-left layouts, and skipping non-focusable items.
  • Adds a Gallery page demonstrating icon-and-text items and selection binding.

Other information

The control styling, selection indicator, focus behavior, and keyboard interaction follow the corresponding WinUI 3 control.

image image

A-Words added 7 commits July 7, 2026 22:27
Add WinUI 3 SelectorBar control for WPF, a lightweight control that
lets users switch between a small number of different views or data sets.

New files:
- SelectorBar.cs: Main control derived from ListBox with single selection
  enforcement, keyboard navigation (Left/Right/Home/End), and a typed
  SelectionChanged event.
- SelectorBarItem.cs: Item container with Text (string) and Icon
  (IconElement) dependency properties.
- SelectorBarSelectionChangedEventArgs.cs: Typed event args for
  selection changes.
- SelectorBar.xaml: Fluent Design styles matching WinUI 3 source:
  - Hover/Pressed only change foreground color (background stays transparent)
  - Selection indicator is a small centered pill (16x3px) using Opacity
    (not Visibility) so content never shifts on selection
  - Padding, spacing and theme resources aligned with WinUI 3
Add a SelectorBar demo page under the Navigation category, mirroring the
structure of other control pages (TabControl, RadioButton). A SelectorBar
with text+icon items drives a content area that updates on selection via
two-way SelectedIndex binding.

- Add SelectorBarPage + SelectorBarViewModel
- Register "SelectorBar" in the Navigation sidebar (MainWindowViewModel)
- No Documentation button; HeaderText "Standard SelectorBar."
Mirror WinUI 3's PART_SelectionVisual for the selection indicator:
- Border -> Rectangle with RadiusX=0.5 / RadiusY=1
- Width 16 -> 4 base; ScaleTransform animates ScaleX 1->4 on select
  (167ms, KeySpline 0,0,0,1) -> 16px final, centered via RenderTransform
- Opacity 0->1 animated in; instant snap back on deselect (no exit anim)
- Disabled trigger: Background -> Fill
Mirror WinUI 3 SelectorBar::OnGotFocus: when the control receives focus
with no selection (or a non-focusable selected item), select the first
focusable item so the pill appears and SelectionChanged fires. Without
this, Tab-focusing an uninitialized SelectorBar (SelectedIndex == -1)
left no selection and raised no event.
Left/Right were fixed-mapped to -1/+1 index steps, so in a RightToLeft
layout (items visually reversed) pressing Right moved visually left.

Treat the key as a visual direction and invert the index delta inside
MoveSelection when FlowDirection == RightToLeft. The no-selection
fallback stays anchored to the visual start/end (Right -> first,
Left -> last) in both directions; LTR behavior is unchanged.
IsSelectableIndex only checked IsEnabled, so an item with
Focusable=False or Visibility=Collapsed could still be selected on
first focus and during arrow navigation (e.g. SelectedIndex became 0
for a non-focusable first item).

Add an IsFocusable helper checking IsEnabled && Focusable && IsVisible
(WPF's focusability triad, mirroring WinUI's Visibility + IsEnabled +
IsTabStop - Focusable is WPF's focus gate; WPF's IsTabStop only governs
tab order and is intentionally not required). Applied to both the
direct-item and data-bound branches, so OnGotFocus, MoveSelection, and
SelectFirst/Last all skip non-focusable items.
@A-Words A-Words requested a review from pomianowski as a code owner July 7, 2026 20:16
@github-actions github-actions Bot added controls Changes to the appearance or logic of custom controls. styles Topic is related to styles PR Pull request gallery WPF UI Gallery dotnet release labels Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

controls Changes to the appearance or logic of custom controls. dotnet gallery WPF UI Gallery PR Pull request release styles Topic is related to styles

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant