Skip to content

ItemsStackPanel wasn't propagating correctly measure/arrange phases after invalidation - #484

Merged
carldebilly merged 4 commits into
masterfrom
dev/cdb/bugs/itemsstackpanel-measure
Jan 9, 2019
Merged

carldebilly merged 4 commits into
masterfrom
dev/cdb/bugs/itemsstackpanel-measure

Conversation

@carldebilly

Copy link
Copy Markdown
Member

Bugfix

Controls calling .InvalidateMeasure() or .InvalidateArrange() when hosted in a virtualized list view (ItemsControl using a ItemsStackPanel) were not remeasured nor rearranged.

What is the current behavior?

The Measure phase of an ItemsStackPanel is not actually measuring its children. The method is
used to calculate the virtualization and check if more items are required. Only newly added items
are getting measured (and arranged).

This faulty behavior is preventing images from stretching correctly. Since
their stretch values are calculated once the image is loaded (because we
need to know the physical dimension of the image), an InvalidateMeasure
were issued on the loaded event. Hosting an image in a virtualized list were
preventing correct stretching of images, because the Arrange method were
never called after the invalidation.

What is the new behavior?

New behaviors are added in this PR:

  1. On re-Measure, If the size is changed, the list is cleared and recreated.
    THIS IS OBVIOUSLY A HACK.
  2. On re-Measure, If the size DID NOT changed, the children items are simply remeasured.
  3. On initial Arrange (when an item is added to the list), the calculated Rect is persisted.
  4. On re-Arrange, all children items are being rearranged with the same size.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes
  • Updated the Release Notes
  • Associated with an issue (GitHub or internal)

Internal Issue (If applicable):

@carldebilly carldebilly added kind/bug Something isn't working platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform labels Jan 8, 2019
@carldebilly

Copy link
Copy Markdown
Member Author

@davidjohnoliver Your input on this PR would be important.

@carldebilly
carldebilly force-pushed the dev/cdb/bugs/itemsstackpanel-measure branch from 55bba0a to bdc9454 Compare January 8, 2019 20:13
carldebilly and others added 4 commits January 9, 2019 09:58
to let measure & arrange phase propagate through children controls.
This hack won't allow items to change their size, but that's better than before.
when the physical of the image is already known from a previous measure.
@carldebilly
carldebilly force-pushed the dev/cdb/bugs/itemsstackpanel-measure branch from bdc9454 to 7a276ef Compare January 9, 2019 15:03
@carldebilly
carldebilly merged commit eb9df9c into master Jan 9, 2019
@carldebilly
carldebilly deleted the dev/cdb/bugs/itemsstackpanel-measure branch January 9, 2019 16:27
@davidjohnoliver

Copy link
Copy Markdown
Contributor

@davidjohnoliver Your input on this PR would be important.

Agreed, it's a hack. :p

kazo0 pushed a commit to kazo0/uno that referenced this pull request Mar 6, 2026
…lockStyles

Dev/math/add text block styles
MartinZikmund added a commit that referenced this pull request May 28, 2026
MenuFlyout.Items and CommandBarFlyout.PrimaryCommands/SecondaryCommands
host their items in logical-only collections — they're not visual
descendants of Popup.Child until the presenter's template materialises
during the upcoming layout pass. The previous fix (cdead2e) propagated
the popup's theme to Child but NotifyThemeChanged only walks visual
descendants, so the items kept the {ThemeResource} brushes they resolved
against the application's global active theme at XAML parse time. The
first frame then rendered with the wrong-theme brush, producing the
visible first-open flash described in kahua-private #480 (light text on
light background before the async corrective theme walk converged).

After NotifyThemeChanged on Child, walk AssociatedFlyout's logical-only
item collections and call NotifyThemeChanged on each. This re-resolves
their {ThemeResource} bindings against the popup's theme before the first
measure / render. Covers MenuFlyout (Items) and CommandBarFlyout
(PrimaryCommands + SecondaryCommands), which also covers TextCommandBarFlyout
— the TextBox edit context menu (Cut/Copy/Paste) where the user
originally reported the flash. NotifyThemeChanged honours each item's
own RequestedTheme override and short-circuits on no-op, so it is safe
for already-correct items.

Tests: add a flash-detection test to Given_MenuFlyout and Given_CommandBarFlyout
that registers a PropertyChangedCallback on the item's Foreground and
snapshots the value at every lifecycle checkpoint; asserts the brush is
already the Light sentinel at the synchronous return of ShowAt (when the
popup is in the tree and the first render is about to happen) and never
the Dark sentinel at any user-visible checkpoint.

Refine #480 / #484 repro comments in Given_ListViewBase and Given_ToolTip
to explain how the same single XAML test runs on Uno (app-theme pinned to
Dark via ThemeHelper.UseApplicationDarkTheme) vs native WinUI (Light-host
baseline, since the app-theme pin is not available there).
MartinZikmund added a commit that referenced this pull request Jun 1, 2026
MenuFlyout.Items and CommandBarFlyout.PrimaryCommands/SecondaryCommands
host their items in logical-only collections — they're not visual
descendants of Popup.Child until the presenter's template materialises
during the upcoming layout pass. The previous fix (cdead2e) propagated
the popup's theme to Child but NotifyThemeChanged only walks visual
descendants, so the items kept the {ThemeResource} brushes they resolved
against the application's global active theme at XAML parse time. The
first frame then rendered with the wrong-theme brush, producing the
visible first-open flash described in kahua-private #480 (light text on
light background before the async corrective theme walk converged).

After NotifyThemeChanged on Child, walk AssociatedFlyout's logical-only
item collections and call NotifyThemeChanged on each. This re-resolves
their {ThemeResource} bindings against the popup's theme before the first
measure / render. Covers MenuFlyout (Items) and CommandBarFlyout
(PrimaryCommands + SecondaryCommands), which also covers TextCommandBarFlyout
— the TextBox edit context menu (Cut/Copy/Paste) where the user
originally reported the flash. NotifyThemeChanged honours each item's
own RequestedTheme override and short-circuits on no-op, so it is safe
for already-correct items.

Tests: add a flash-detection test to Given_MenuFlyout and Given_CommandBarFlyout
that registers a PropertyChangedCallback on the item's Foreground and
snapshots the value at every lifecycle checkpoint; asserts the brush is
already the Light sentinel at the synchronous return of ShowAt (when the
popup is in the tree and the first render is about to happen) and never
the Dark sentinel at any user-visible checkpoint.

Refine #480 / #484 repro comments in Given_ListViewBase and Given_ToolTip
to explain how the same single XAML test runs on Uno (app-theme pinned to
Dark via ThemeHelper.UseApplicationDarkTheme) vs native WinUI (Light-host
baseline, since the app-theme pin is not available there).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants