Repository navigation
Description
Current behavior
If the Setter for ControlTemplate of an ItemsControl is set before the Setter for ItemContainerStyle, the ItemContainerStyle will never be set when adding items to the ItemsControl directly in the XAML.
Expected behavior
How to reproduce it (as minimally and precisely as possible)
ItemContainerStyleBug.zip
Sample repro app attached above
Define a base style for a custom ItemsControl:
<Style x:Key="MyBaseItemsControlStyle"
TargetType="local:MyItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:MyItemsControl">
<Grid>
<ItemsPresenter />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>Define an ItemsControl style based on the one you just created:
<Style x:Key="MyBlueItemsControlStyle"
BasedOn="{StaticResource MyBaseItemsControlStyle}"
TargetType="local:MyItemsControl">
<Setter Property="ItemContainerStyle"
Value="{StaticResource MyBlueItemsControlItemStyle}" />
</Style>Define a style for the custom ItemsControl's Item:
<Style x:Key="MyBlueItemsControlItemStyle"
TargetType="local:MyItem">
<Setter Property="Background"
Value="Blue" />
<Setter Property="BorderBrush"
Value="CornflowerBlue" />
<Setter Property="BorderThickness"
Value="5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:MyItem">
<Grid Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>In your MainPage, set the Page content to:
<Grid Margin="0,100,0,0">
<StackPanel Spacing="20">
<TextBlock Text="Using ItemsSource" />
<local:MyItemsControl Style="{StaticResource MyBlueItemsControlStyle}"
ItemsSource="{x:Bind Items}" />
<TextBlock Text="Directly added in XAML" />
<local:MyItemsControl Style="{StaticResource MyBlueItemsControlStyle}">
<local:MyItem Content="1" />
<local:MyItem Content="2" />
<local:MyItem Content="3" />
<local:MyItem Content="4" />
<local:MyItem Content="5" />
</local:MyItemsControl>
</StackPanel>
</Grid>Notice that the first ItemsControl is displaying the Items properly, but the second ItemsControl is not applying the MyBlueItemsControlItemStyle
Workaround
Define the ItemContainerStyle and the Template within the same Style, ensuring that the ItemContainerStyle Setter appears BEFORE the Template Setter
Works on UWP/WinUI
Yes
Environment
Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
NuGet package version(s)
No response
Affected platforms
WebAssembly, Android, iOS, macOS (AppKit), Mac Catalyst, Skia (WPF), Skia (GTK on Linux/macOS/Windows), Skia (Linux Framebuffer), Skia (Tizen)
IDE
Visual Studio 2022
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
No response


Activity
[-]ItemContainerStyle is not always applied for ItemsControl[/-][+]`ItemContainerStyle` is not always applied for `ItemsControl`[/+]github-actions commentedon Aug 7, 2025
Hey there — just a heads-up that this issue has been quiet for over a year. If there’s no update or comment in the next 10 days, it’ll be closed automatically. Feel free to remove the stale label or drop a note to keep it open.
MartinZikmund commentedon Aug 7, 2025
Still relevant
test: Verify ItemContainerStyle applied from BasedOn style after Temp…
MartinZikmund commentedon Apr 8, 2026
Repro generator
Runtime test(s) added in branch
dev/mazi/repro/10786:src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ListViewBase.cs→When_ItemContainerStyle_Set_In_BasedOn_Style_After_Template