Skip to content

Fix Segmented selection automation providers - #892

Open
azchohfi wants to merge 3 commits into
CommunityToolkit:mainfrom
azchohfi:azchohfi-fix-segmented-automation-peers
Open

azchohfi wants to merge 3 commits into
CommunityToolkit:mainfrom
azchohfi:azchohfi-fix-segmented-automation-peers

Conversation

@azchohfi

@azchohfi azchohfi commented Nov 21, 2026 •

Copy link
Copy Markdown

Fixes

Addresses the missing selection-provider support reported in #192 and #295. These issues also cover announcements and item-position information, so this PR does not close them or claim those broader contracts are fixed.

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

Segmented derives from ListViewBase, but it does not create a selection-aware automation peer. Its inherited peer exposes neither the root Selection provider nor item SelectionItem providers, even when native selection changes.

What is the new behavior?

Segmented creates a SegmentedAutomationPeer derived from ListViewBaseAutomationPeer. The peer creates native ListViewItemDataAutomationPeer instances for items. Naming, child enumeration, selection, and event behavior stay with the native implementation.

The change adds native UI regression cases for string items and explicit containers, named roots, selection identity, provider Select, disabled rejection, and retained item identity after collection changes. The assertions check both the item states and the identity of the provider returned by root Selection. The test file is included explicitly in the shared test project.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • Tested code with current supported SDKs
  • New component
    • Documentation has been added
    • Sample in sample app has been added
    • Analyzers are passing for documentation and samples
    • Icon has been created (if new sample) following the Thumbnail Style Guide and templates
  • Tests for the changes have been added (if applicable)
  • Header has been added to all new source files
  • Contains NO breaking changes

This fixes an existing component. The new-component checklist does not apply.

Other information

Build validation

The production change was validated at 46693f9ae7810dea2f98161d7f5f5157181cfe92, based on a2fa47ad72cb95ed81f3ff0885da627a5fd6c14e, with tooling f02adf9e2d1ec1fd4865116bc786e217298985af. Test-only follow-ups through c8380aa5f6971c98e75c97d89dffcc504c4641f5 were compiled on both native test heads. The unchanged SDK policy selected .NET SDK 10.0.404. Native source builds used the repository's WinUI 1.8.260204000 and CsWinRT 2.2.0 pins.

The commands used process-local CLI and NuGet caches. The official NuGet v2 source was supplied only for these restores because the v3 endpoint failed TLS negotiation. No repository feeds, dependency pins, build gates, or global settings changed.

MSBuild.exe components\Segmented\src\CommunityToolkit.WinUI.Controls.Segmented.csproj -restore -p:RestoreSources=https://www.nuget.org/api/v2/ -p:EnabledMultiTargets=wasdk -p:WinUIMajorVersion=3 -p:Configuration=Release -m:1 -nr:false -v:minimal -nologo

Passed for net8 and net9 Windows 26100.

MSBuild.exe components\Segmented\heads\Tests.Wasdk\Segmented.Tests.Wasdk.csproj -restore -p:RestoreSources=https://www.nuget.org/api/v2/ -p:EnabledMultiTargets=wasdk -p:WinUIMajorVersion=3 -p:Configuration=Release -p:Platform=x64 -m:1 -nr:false -v:quiet -nologo

Passed for the latest test revision. This local command compiled the native MSTest head without executing it. The separate CI execution is recorded below.

MSBuild.exe components\Segmented\src\CommunityToolkit.WinUI.Controls.Segmented.csproj -restore -p:RestoreSources=https://www.nuget.org/api/v2/ -p:EnabledMultiTargets=uwp -p:WinUIMajorVersion=2 -p:PackageIdVariant=Uwp -p:Configuration=Release -m:1 -nr:false -v:minimal -nologo

Passed for UAP 17763 and net8/net9 Windows 26100 after shortening the private cache path to avoid MAX_PATH.

MSBuild.exe components\Segmented\heads\Tests.Uwp\Segmented.Tests.Uwp.csproj -restore -p:RestoreSources=https://www.nuget.org/api/v2/ -p:EnabledMultiTargets=uwp -p:WinUIMajorVersion=2 -p:PackageIdVariant=Uwp -p:Configuration=Release -p:Platform=x64 -m:1 -nr:false -v:quiet -nologo

Passed for the latest test revision after shortening only the generated head's output/intermediate paths to avoid MAX_PATH. Local native MSTest head compilation only, not test execution.

MSBuild.exe components\Segmented\src\CommunityToolkit.WinUI.Controls.Segmented.csproj -restore -p:RestoreSources=https://www.nuget.org/api/v2/ -p:EnabledMultiTargets=wasm -p:WinUIMajorVersion=3 -p:Configuration=Release -m:1 -nr:false -v:minimal -nologo

Passed for the declared Uno net9 library target. No Uno runtime test was run.

Native CI validation

The WinAppSDK CI job passed on c8380aa5f6971c98e75c97d89dffcc504c4641f5 using the pinned WinUI 1.8.260204000 package. It ran the repository's native test command.

vstest.console.exe ./tooling/**/CommunityToolkit.Tests.wasdk.build.appxrecipe /Framework:FrameworkUap10 /logger:"trx;LogFileName=wasdk.trx" /Blame:"CollectDump;DumpType=Full;CollectHangDump;TestTimeout=30m;HangDumpType=Full" /Diag:"C:\a\Windows\Windows/vstest-diagnostic-log.txt"

Passed. The full component run reported 385 passed and 3 skipped out of 388 tests. All six new Segmented tests passed, including root provider identity, SelectionItem.Select, disabled-element HRESULT and unchanged selection, and retained peer identity after reorder/removal.

Other matrix jobs fail before compilation during Uno workload installation. A repeated failure is a conflict between the .NET 11 and .NET 10 Mono workload manifests. The workflow, tool manifest, SDK policy, and tooling revision are unchanged from the source parent. This PR does not suppress or bypass those failures. The UWP CI job completed successfully, but VSTest reported "No test is available in entrypoint\CommunityToolkit.Tests.Uwp.exe." That is build success, not evidence that the UWP Segmented tests ran.

Focused runtime evidence

A standalone diagnostic reproduction is available in microsoft/microsoft-ui-reactor#1650. It demonstrates the gap in the published 8.3.260402-preview2 package and does not contain this native fix. The source-matched candidate and mutation results below are separate evidence.

Source-matched parent and candidate packages were compared in unpackaged consumers with identical resolved dependencies on net10 Windows 26100 and WinUI 2.2.1.

  • Both native Segmented forms matched six selection identities at indices 0/1, giving 12 native observations. The mapped consumer matched another six.
  • All four native ListView positive controls matched six of six identities.
  • Independent UIA observations showed candidate string items, explicit containers, and ListView changing selected state through 0 -> 1 -> 0. With the source-parent package, only ListView exposed those state changes.
  • Removing the control's automation-peer hook removed root/item selection providers. Removing only the item-peer factory retained root Selection but caused GetSelection to throw 0x8000FFFF. The factory-off native capture stopped at string-item/index 0, so its explicit-container form was not observed.

These historical unpackaged runs are focused provider/identity evidence, separate from the newer native CI test results above. OS exit codes and full TAP-lane completion were not captured for those live probes. Narrator announcements, PositionInSet/SizeOfSet, and the named-root UWP/Narrator crash remain unverified. No local Appx/MSIX deployment was performed. This does not claim #193 or #581 is fixed.

Reuse the native ListViewBase selection provider and ListView item data peers. Add native UI regression tests for selection identity, provider actions, disabled controls, and collection changes.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests check only GetSelection() array length, so they could pass even if the returned provider represents the wrong selected item, including after collection changes.

1 open issue
What changed in this PR

This PR adds native selection-aware automation peers to Segmented, addressing the provider-support portion of #192 and #295 without claiming broader Narrator or item-position fixes.

Changes:

  • Connects Segmented to a list-based automation peer with native item peers.
  • Adds Windows regression tests for selection providers, disabled selection, and identity after collection changes.
  • Documents the selection patterns and accessible naming.
File Description
components/​Segmented/​tests/​Test_Segmented_AutomationPeer.cs Adds native selection-provider regression tests.
components/​Segmented/​tests/​Segmented.Tests.projitems Includes the new tests in the shared project.
components/​Segmented/​src/​Segmented/​SegmentedAutomationPeer.cs Adds the root peer and native item-peer factory.
components/​Segmented/​src/​Segmented/​Segmented.cs Hooks the control into the new automation peer.
components/​Segmented/​src/​ReadMe.md Documents Windows selection support and accessible naming.

Review effort: Balanced

Resolve the native provider returned by GetSelection and check the expected logical item in every selection assertion, including retained peers after collection changes.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The native UIA tests were only compiled, leaving provider selection, disabled rejection, retained-peer behavior, and compatibility with the minimum supported WinUI 1.8 runtime unverified on Windows.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Assert UIA_E_ELEMENTNOTENABLED for disabled selection and re-enable before querying selection providers. Reorder unselected items with remove/insert instead of a Move reset, and retain identity assertions for surviving peers after removal.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Windows runtime validation is still needed for provider selection, disabled rejection, and retained-peer behavior because the added tests remain unexecuted and minimum-supported WinUI 1.8 compatibility is unverified.

No open issues 🎉

Review effort: Balanced

@azchohfi

Copy link
Copy Markdown
Author

Windows runtime validation is still needed for provider selection, disabled rejection, and retained-peer behavior.

The native WinAppSDK CI job now passes at c8380aa. All six Segmented tests ran against WinUI 1.8.260204000, including those paths and root selection-provider identity. The full component run has 385 passed and 3 skipped. UWP is still running, and the other matrix failures occur during workload setup.

@niels9001
niels9001 requested a balanced review from Copilot November 21, 2026 06:46
@niels9001
niels9001 enabled auto-merge (squash) November 21, 2026 06:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

UWP CI discovered no tests for the shared automation-peer change, leaving native Selection/SelectionItem and named-root accessibility behavior dependent on human runtime validation.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants