Skip to content

ListView does not use ItemTemplateSelector when ItemsPanel is configured #10376

@mattiferg

Description

@mattiferg

Describe the bug

When a ListView has the ItemsPanel explicitly configured then the configured ItemTemplateSelector is not honoured.
This means that we cannot add spacing, orientation etc. to a list with more than one item template.

Steps to reproduce the bug

<Grid ColumnDefinitions="*,*" RowDefinitions="Auto,*">

    <TextBlock Grid.Row="0" Grid.Column="0" Text="Works"/>
    <Border Grid.Row="1" Grid.Column="0" Background="Yellow">
        <ListView x:Name="GoodList" ItemsSource="{x:Bind MyItems}" ItemTemplateSelector="{StaticResource MyTemplateSelector}"/>
    </Border>

    <TextBlock Grid.Row="0" Grid.Column="1" Text="Does not work"/>
    <Border Grid.Row="1" Grid.Column="1" Background="Pink">
        <ListView x:Name="BadList" ItemsSource="{x:Bind MyItems}" ItemTemplateSelector="{StaticResource MyTemplateSelector}">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
        </ListView>
    </Border>
</Grid>

ListView named GoodList applies the template selector. ListView named BadList does not.

Expected behavior

Both lists in the repro should look the same.

Screenshots

Image

NuGet package version

WinUI 3 - Windows App SDK 1.6.5: 1.6.250205002

Windows version

Windows 11 (24H2): Build 26100

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageIssue needs to be triaged by the area owners

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions