Skip to content

Bug: ListView doesn't render its items when using CollectionViewSource & NativeAot #2001

Open
@tipa

Description

@tipa

Description

When using a grouped CollectionViewSource and Native AOT, the items of a ListView aren't shown - only the grouping headers

Image

Steps To Reproduce

MainWindow.xaml

    <ListView ItemsSource="{x:Bind csv.View, Mode=OneWay}">
        <ListView.ItemTemplate>
            <DataTemplate x:DataType="sys:DateTime">
                <TextBlock Text="{x:Bind}"/>
            </DataTemplate>
        </ListView.ItemTemplate>
        <ListView.Resources>
            <CollectionViewSource x:Name="csv" ItemsPath="Dates" IsSourceGrouped="True" />
        </ListView.Resources>
        <ListView.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate x:DataType="l:DateGroup">
                        <TextBlock Text="{x:Bind GroupingDate}" FontWeight="SemiBold" TextAlignment="Center"/>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </ListView.GroupStyle>
    </ListView>

MainWindow.xaml.cs

public sealed partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        csv.Source = new List<DateGroup>
        {
            new() {
                GroupingDate = new DateTime(2023, 10, 1),
                Dates = [new DateTime(2023, 10, 1), new DateTime(2023, 10, 2)]
            },
            new() {
                GroupingDate = new DateTime(2024, 10, 1),
                Dates = [new DateTime(2024, 10, 1), new DateTime(2024, 10, 2)]
            },
        };
    }
}

[WinRT.GeneratedBindableCustomProperty]
sealed partial class DateGroup
{
    public DateTime GroupingDate { get; set; }
    public List<DateTime> Dates { get; set; }
}

project.csproj

  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <SelfContained>true</SelfContained>
    <PublishAot>true</PublishAot>
  </PropertyGroup>

example project: test.zip

Expected Behavior

Image

Version Info

Microsoft.Windows.CsWinRT 2.2.0
Microsoft.WindowsAppSDK 1.8.250410001-experimental1

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions