Skip to content

CollectionView throws NRE when ItemTemplate uses a ViewCell as parent #24379

Closed
@AndreasReitberger

Description

Description

If using a ViewCell in the DataTemplate, the application throws an exception (NRE).

<CollectionView
    ItemsSource="{Binding Events}"
    SelectionMode="None"
    >
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Label 
                    LineBreakMode="WordWrap" 
                    Style="{StaticResource SubHeadline}" 
                    Text="{Binding .}"
                    FontAttributes="Bold"
                    VerticalTextAlignment="Center"
                    />
            </ViewCell>
        </DataTemplate>
    </CollectionView.ItemTemplate>
    <CollectionView.EmptyView>
        <Label 
            Text="No items..."
            VerticalTextAlignment="Center"
            HorizontalTextAlignment="Center"
            />
    </CollectionView.EmptyView>
</CollectionView>

Steps to Reproduce

  1. Fork the repro
  2. Run it on windows (not tested any other platforms)
  3. See that an exception is thrown
  4. Replace ViewCell with a Grid and see that it is working afterwards

Link to public reproduction project repository

https://github.com/AndreasReitberger/MauiCollectionViewBug

Version with bug

8.0.80 SR8

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

Replace the ViewCell with a Grid or something similar.

Relevant log output

No response

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions