Repository navigation
Fix ItemsView multi-select checkmark flicker on window resize (#383) - #648
Merged
Alexandre Zollinger Chohfi (azchohfi) merged 6 commits intoJun 24, 2026
Conversation
In a SelectionMode=Multiple ItemsView the per-item selection checkmark visibly faded out/in on every realized row during a window drag-resize. Root cause: WinUI's ItemsView flips each realized ItemContainer's internal MultiSelectMode (Auto <-> Auto|Multiple) on every recycle round-trip, each flip running the MultiSelectStates.Multiple opacity storyboard with useTransitions:true. Reactor's host re-runs a full layout pass on every resize tick, which drives the inner ItemsRepeater to recycle/realize its working set dozens of times per gesture even though nothing the ItemsView owns actually moved (the ItemsView/ScrollView/repeater geometry is constant across the gesture). The recycle storm is intrinsic WinUI ItemsRepeater viewport-manager behavior and cannot be suppressed in FlexPanel without regressing ItemsView width; only the useTransitions:true fade is visible. Mitigation: ItemContainerSelectionFlickerGuard collapses the Multiple state's opacity storyboard to zero duration on each realized container, so WinUI's animated GoToState snaps the checkmark to full opacity in the same UI tick instead of fading it. MultiSelectMode and its enum are [MUX_INTERNAL] so the guard works purely through the public MultiSelectStates VisualStateGroup, mutating only the container's own per-instance template storyboard (no GoToState re-entrancy, no shared resource). Armed idempotently from ElementFactory.GetElement when a realized control is an ItemContainer. Adds a selftest regression fixture that drives the exact Single->Multiple animated transition and asserts the checkmark opacity is snapped to 1.0 rather than left mid-fade. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
requested a review
from Chris Anderson (codemonkeychris)
as a code owner
June 23, 2026 07:12
Anchor the regression fixture on a real realized ItemContainer from a live SelectionMode=Multiple ItemsView and add an un-guarded fade proof: restore a non-zero keyframe on the Multiple storyboard and assert the identical Single->Multiple transition fades (opacity 0.000), then re-collapse and assert it snaps (1.000). This guarantees the snap assertion is not green-by-construction and would catch a regressed/absent guard. Co-authored-by: Copilot <[email protected]>
Per PR-review triage (M3, must-fix): the regression fixture now covers BOTH the guard mechanism AND its production activation, so a silent break in either is caught. Part A (mechanism): realize an ItemContainer via a raw WinUI ItemsView (never through Reactor's ElementFactory, so un-armed), prove the Single->Multiple transition fades (opacity 0.000), then call ItemContainerSelectionFlickerGuard.Ensure directly and prove it snaps (1.000). Part B (wiring): realize an ItemContainer via a Reactor ItemsView and assert the GetElement-armed guard already collapsed the storyboard so the transition snaps (1.000) with no direct Ensure call. If the GetElement->Ensure wiring breaks, Part B fails while Part A still passes. Also: comment at the GetElement arming site explaining the ItemContainer scope is intentional (LazyVStack/HStack use ItemsRepeater not ItemContainer; the Multiple storyboard only runs for multi-select containers), and an XML-doc note on Holder.Neutralized re re-templated storyboards. No production behavior change. Co-authored-by: Copilot <[email protected]>
…L1/L3/L4) Final PR-review triage round for #383. L4 (correctness): TryNeutralize now sets Neutralized=true before the group-absent return, symmetric with the no-Multiple-state branch, so an unusual ItemContainer template without a MultiSelectStates group no longer retains the Loaded handler or re-walks the visual tree on every recycle. L1 (test): Part B now polls (Harness.WaitFor) until the guard has actually collapsed the Multiple storyboard before asserting, instead of relying on a fixed two-render-pass budget — removes a potential CI flake on slow runners. L3 (test): new Part C forces a real recycle round-trip (toggle the ItemsView between two disjoint keyed item sets via a state button, so the inner ItemsRepeater clears + re-prepares its containers — the production OnItemsRepeaterElementClearing/Prepared trigger) and asserts a realized container still snaps afterward. Closes the gap between 'guard collapses the storyboard' and 'guard survives the recycle that causes the flicker'. L2/L5 skipped per triage. No production behavior change beyond the L4 edge-case give-up. Co-authored-by: Copilot <[email protected]>
…ryboardCollapsed Refactor the nested foreach in the IsMultipleStoryboardCollapsed test helper to filter explicitly with .Where(...) / .OfType<>() instead of in-loop guard clauses, per the github-code-quality review. No behavior change — flicker fixture still 12/12. Co-authored-by: Copilot <[email protected]>
…detach, docs Addresses the meaningful findings from the re-run pr-review of PR #648 (#383): M1 (test-coverage): Part C of ItemsView_MultiSelect_CheckmarkDoesNotFlicker no longer relies on a fixed 2-render-pass budget that could pass vacuously. It now polls (WaitFor) and asserts the realized dataset genuinely swapped each way: an AltCatalog-only item (Xigua) becomes realized and the bound ItemsView.ItemsSource count changes (5<->3). Reading the source count is pool-proof - WinUI keeps cleared containers parented in its recycle pool with stale text, so a tree-wide FindText would still match the old set. L3 (correctness): ItemContainerSelectionFlickerGuard.Ensure now detaches a previously attached Loaded handler whenever TryNeutralize succeeds (synchronously or via the deferred hook), so the one-time handler cannot linger on the container until the next Loaded fires. Adds a DetachLoaded helper and a Holder.OnLoaded field. L2 (alternative-solution): documented why the guard deliberately uses a private ConditionalWeakTable instead of ReactorAttached.StateProperty (must be safe on any ItemContainer, including raw-WinUI ones with no ReactorState). L1 (docs): added a CHANGELOG entry for the #383 fix. Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi)
merged commit Jun 24, 2026
6aeb00a
into
main
28 of 29 checks passed
Alexandre Zollinger Chohfi (azchohfi)
deleted the
azchohfi-fix-itemsview-checkmark-flicker
branch
June 24, 2026 00:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #383.
Symptom
In an
ItemsViewwithSelectionMode=Multiple(e.g. samples/Reactor.TestApp → ItemsView tab), the per-item selection checkmark visibly fades out/in on every realized row while the user drag-resizes the window.Root cause (proven, not surgically fixable in layout)
The fade itself is intrinsic WinUI behavior: on every
ItemsRepeaterrecycle round-trip,ItemsViewflips each realizedItemContainer's internalMultiSelectMode(Auto↔Auto|Multiple), and each flip runs theMultiSelectStates.Multipleopacity storyboard (PART_SelectionCheckbox.Opacity0→1) withuseTransitions: true.What makes it visible in Reactor specifically is frequency: during a window resize Reactor's host re-runs a full layout pass on every tick, which drives the inner
ItemsRepeaterto recycle/realize its working set dozens of times per gesture — even though nothing the ItemsView owns actually moved.I instrumented this exhaustively (headless zero-reconcile repro + per-panel measure/arrange counters + inner ScrollView/repeater geometry logging):
VStack → ItemsView → ScrollView → ItemsRepeater) is never re-measured or re-arranged by FlexPanel — only the outer FlexColumn re-runs — and theScrollViewgeometry is 100% constant (viewport=500, extent=124, offset=0; repeater 700×124), yet the repeater fully re-realizes ~43 items/tick.So the recycle is intrinsic
ItemsRepeaterviewport-manager behavior firing on every ancestor arrange pass, not something FlexPanel does to the ItemsView. I tried two layout-side suppressions (skip the grow-child re-measure; measure the main axis at ∞) — both stopped the churn but broke the ItemsView width (700 → 2696), because the grow child's finite re-measure is load-bearing for cross-axis width propagation. Eliminating the spurious recycle is therefore not possible without regressing layout.Known upstream behavior
This recycle storm is upstream WinUI behavior, not a Reactor layout bug — it matches microsoft/microsoft-ui-xaml#11122 (
ItemsRepeaterre-realizes its working set on every ancestor arrange pass even when its own viewport/extent is unchanged). This PR is a cosmetic mitigation of the visible fade, not a fix for the recycle itself; if/when the upstream issue is resolved the guard becomes a no-op and can be removed.Fix (the brief's endorsed mitigation: stop the checkmark re-animating)
ItemContainer.MultiSelectModeandItemContainerMultiSelectModeare[MUX_INTERNAL], so the property is unreachable from Reactor. Instead, the newItemContainerSelectionFlickerGuardreaches into the publicMultiSelectStatesVisualStateGrouponce the container's template is applied, finds theMultiplestate's opacity storyboard, and collapses its keyframe times to zero. WinUI keeps callingGoToState("Multiple", useTransitions: true)exactly as before, but a zero-duration storyboard snaps the checkmark to full opacity in the same UI tick instead of fading it — so the recycle storm is no longer visible. Selection behavior, the recycle, and final checkmark visibility are unchanged.This is a per-instance, one-time mutation of the container's own template storyboard. It never calls
GoToState(which is not re-entrancy-safe from inside WinUI's own state transitions — an earlierCurrentStateChanged+GoToState(useTransitions:false)approach deadlocked realization), and it touches no shared resource.Pool rent/return safety
The guard is armed idempotently from
ElementFactory<T>.GetElementwhen the realized control is anItemContainer. There is no persistent event subscription to leak across pool reuse — the only handler is a transient, self-removingLoadedhook used when a freshly-mounted container hasn't applied its template yet. State is tracked in aConditionalWeakTable<ItemContainer, Holder>(the same once-per-control wiring pattern the pooling layer already uses for poolable controls): a re-rented container short-circuits onholder.Neutralizedso it is never double-processed, and the collapsed storyboard persists across rent/return because it lives on the container's own template instance.Before / after
[EF]ElementFactory diagnostic): ~3870 Get / 3870 Recycle over the gesture, ~43 items re-realized/tick across ~75–90 ticks (zero-reconcile repro: 3225–3913 depending on scenario). A plainBorderancestor instead of FlexPanel = 0 — confirming it is the repeater's own viewport manager, not Reactor layout.Single → Multipleanimated transition WinUI fires on a recycle and assertsPART_SelectionCheckbox.Opacity == 1.000immediately (snapped). The same test proves the un-guarded path genuinely fades (opacity 0.000 mid-transition with a restored non-zero keyframe) — so the snap assertion is load-bearing, not green-by-construction.Tests
ItemsView_MultiSelect_CheckmarkDoesNotFlicker, now load-bearing on a real realizedItemContainerfrom a liveSelectionMode=MultipleItemsView, with three checks:GetElement-armed guard has already collapsed the storyboard → transition snaps (opacity=1.000).opacity=0.000). A regressed/absent guard would land here.opacity=1.000).ItemsViewselftest suite green.dotnet test tests/Reactor.Tests: 9517 passed, 0 failed (64 skipped).WindowLevel_RuntimeFlip_Topmost(passes in isolation; cross-fixture window-topmost interference, untouched by this change).Scope / overlap note
Surgical: 1 new core file + a 5-line
GetElementwiring + a selftest fixture & registration. No FlexPanel/layout changes. The only shared-file touch issrc/Reactor/Core/ElementFactory.cs— additive, near the end ofGetElement. A sibling effort (#326 / PR #635,RefreshRealizedItems/TryAdoptRealizedReplacement) also touchesElementFactory<T>; this change is additive and localized, but flagging for merge ordering in case of a trivial textual conflict in that file.Co-authored-by: Copilot [email protected]