Skip to content

ItemsControl.ItemContainerStyle set after containers are realized is not applied to them #26423

Open

Description

@MartinZikmund

Current behavior

Severity: Low - setting or swapping ItemContainerStyle (or ItemContainerStyleSelector) on a plain ItemsControl after its containers exist is silently ignored, so runtime style swaps don't show up until the containers are recreated.

On a plain ItemsControl (ContentPresenter containers), assigning ItemContainerStyle after the first layout leaves the already-realized containers unstyled. ListView/GridView are not affected because the ListViewBase family overrides Refresh().

Expected behavior

The style is re-applied to the realized containers. In WinUI, ItemsControl::OnItemContainerStyleChangedImpl calls RefreshContainers() (dxaml/xcp/dxaml/lib/ItemsControl_Partial.cpp, also OnItemContainerStyleSelectorChangedImpl). A native WinUI 3 run (WinAppSDK 2.5.1) of the repro below gives container Opacity 0.5 and 0.5. Uno gives 1 and 1.

How to reproduce it (as minimally and precisely as possible)

  1. Host an ItemsControl with two items and wait for layout.
  2. Assign an ItemContainerStyle with a setter targeting ContentPresenter.
  3. Read the Opacity of the containers.
var ic = new ItemsControl { ItemsSource = new[] { "a", "b" } };
Window.Content = ic;
// wait for layout / loaded
ic.ItemContainerStyle = (Style)XamlReader.Load(
    "<Style xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' TargetType='ContentPresenter'>" +
    "<Setter Property='Opacity' Value='0.5'/></Style>");
// await idle
var c0 = (ContentPresenter)ic.ContainerFromIndex(0);
var c1 = (ContentPresenter)ic.ContainerFromIndex(1);
// WinUI: c0.Opacity == 0.5, c1.Opacity == 0.5
// Uno:   c0.Opacity == 1,   c1.Opacity == 1

Setting the style before the first layout works on both.

Runtime-verified: a runtime test with exactly this repro fails on Skia desktop (Windows) on master 46ea872727d with Expected:<0.5>. Actual:<1>.

Workaround

Reset ItemsSource after changing the style so the containers are recreated.

Works on UWP/WinUI

Yes (container Opacity 0.5 on WinUI 3, WinAppSDK 2.5.1).

Environment

master 46ea872727d, net11.0-desktop, .NET SDK 11.0.100

NuGet package version(s) affected

master 46ea872727d

Affected platforms

All (shared ItemsControl code); runtime-verified on Skia desktop (Windows).

IDE

n/a

Anything else we need to know?

Root cause (source-backed): OnItemContainerStyleChanged only calls Refresh(), and Refresh() is an empty private protected virtual in ItemsControl. Only the ListViewBase family overrides it. ApplyItemContainerStyle only runs when a container is prepared.

A possible fix is to re-run ApplyItemContainerStyle over the realized containers when the style or selector changes (WinUI skips the selector refresh when ItemContainerStyle is set).

Related but different: #10786 is about the order of setters inside a Style, not about changing the style at runtime.

Activity

  1. added
    kind/bug
    triage/untriaged
    project/styling 👔
    project/items 🧾
    platform/all
    difficulty/medium 🤔
    on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty/medium 🤔kind/bugplatform/allproject/items 🧾project/styling 👔triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions