Skip to content

ItemsStackPanel as the ItemsPanel of a plain ItemsControl creates two containers per item, all at offset 0 #25458

Open

Description

@MartinZikmund

Current behavior 🐛

When ItemsStackPanel is used as the ItemsPanel of a plain ItemsControl (not a ListView/GridView), the panel ends up with twice as many children as items: half are zero-sized, never-measured containers, the other half are real containers. In an app where the panel isn't given a fixed size (e.g. HorizontalAlignment="Right" in a horizontally unbounded parent) the panel measured to width 0 and nothing was drawn, with all children arranged at the same offset.

Observed with 6 items, ItemsControl of 300x300 (Skia Desktop):

panel 300x300; children: 0x0@0,0 | 0x0@0,0 | 0x0@0,0 | 0x0@0,0 | 0x0@0,0 | 0x0@0,0 | 9.3x19.3@0,0 | 9.3x19.3@0,0 | 9.3x19.3@0,0 | 10.7x19.3@0,0 | 8x19.3@0,0 | 7.3x19.3@0,0

Children.Count is 12 for 6 items, and every child is at offset 0,0 (the items are not stacked), for Orientation Horizontal and Vertical alike.

Expected behavior 🎯

One container per item, stacked along the panel orientation. WinUI supports ItemsStackPanel in a plain ItemsControl: its native test suite has ItemsStackPanelIntegrationTests::CanStackItemsHorizontally / CanStackItemsVertically, which use an ItemsControl with an ItemsStackPanel and expect items at (100 * i, 100) / (100, 100 * i).

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

  1. Add this to a page:
    <ItemsControl x:Name="ic" Width="300" Height="300">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <ItemsStackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
    and set ic.ItemsSource = new[] { "A", "B", "C", "D", "E", "F" };
  2. Once loaded, find the ItemsStackPanel in the visual tree.
  3. Result: panel.Children.Count == 12, children all at ActualOffset == (0, 0). Expected: 6 children at increasing X.

Equivalent runtime test (Uno.UI.RuntimeTests):

[TestMethod]
[RunsOnUIThread]
public async Task When_ItemsStackPanel_Is_ItemsPanel_Of_ItemsControl()
{
    var ic = new ItemsControl
    {
        Width = 300, Height = 300,
        ItemsSource = new[] { "A", "B", "C", "D", "E", "F" },
        ItemsPanel = (ItemsPanelTemplate)XamlReader.Load(
            "<ItemsPanelTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'><ItemsStackPanel Orientation='Horizontal'/></ItemsPanelTemplate>"),
    };
    WindowHelper.WindowContent = ic;
    await WindowHelper.WaitForLoaded(ic);
    await WindowHelper.WaitForIdle();

    var panel = VisualTreeUtils.FindVisualChildByType<ItemsStackPanel>(ic);
    Assert.AreEqual(6, panel.Children.Count); // actual: 12
}

Confirmed at runtime on Skia Desktop (net11.0-desktop, master 4393a80). I first hit this in a real app (Uno.Sdk 7.0.0-dev.73) on desktop and WASM, where it showed up as a zero-width panel with nothing drawn; I did not re-run WASM on master.

Workaround 🛠️

Use a StackPanel (or VirtualizingStackPanel) as the ItemsPanel of a plain ItemsControl, or use a ListView if you need ItemsStackPanel.

Works on UWP/WinUI

Yes. Backed by the WinUI C++ sources (dxaml/test/native/external/controls/itemsstackpanel/ItemsStackPanelIntegrationTests.cpp, CanStackItemsHorizontally / CanStackItemsVertically), not by running a native WinUI repro.

Environment

Master 4393a80, Skia Desktop (net11.0-desktop). Initially seen on Uno.Sdk 7.0.0-dev.73, desktop and WASM (Skia).

Anything else?

Suspected root cause (code inspection, not proven by a fix):

  • ItemsStackPanel is an IVirtualizingPanel whose ItemsStackPanelLayout generates its own containers via VirtualizingPanelGenerator (ItemsStackPanel.cs).
  • ItemsControl.ShouldItemsControlManageChildren is ItemsPanelRoot == InternalItemsPanelRoot (ItemsControl.cs#L130), so a plain ItemsControl also adds its own containers into the panel.
  • Only Selector overrides it to back off when the panel is an IVirtualizingPanel (Selector.managed.cs#L22). The two generators then both populate the same Children collection.

This is a different problem from #25266 (GetItemsHostOrientations), which only concerns the orientation reported by Selector.

Activity

  1. added
    kind/bug
    triage/untriaged
    project/items 🧾
    platform/all
    difficulty/medium 🤔
    on Oct 14, 2026
  2. removed
    triage/untriaged
    on Oct 29, 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 🧾

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions