Skip to content

[Windows] CollectionView.EmptyView can not be removed by setting it to Null #18657

@drasticactions

Description

@drasticactions

Description

In WinUI, If you try to programmatically remove an EmptyView on a CollectionView by setting it to null, it will not be removed. The reference will be set to null in the CollectionView, but the actual View will still be present on the screen and in memory. Adding an item to the CollectionView invokes internal events within MAUI to remove the view, and users will not see it as it becomes hidden, but it's still present in the actual WinUI layout representation.

Beyond memory and usage considerations, I believe this also leads to issues with VisualDiagnostics and Hot Reload. For example, if you try to remove an EmptyView with Hot Reload, it won't seem to work. If you add an item to the CollectionView, events are invoked in MAUI to say that the EmptyView was removed from the parent CollectionView, but the actual instance wasn't, leading to a bad state for VisualDiagnostics and the Live Visual Tree.

I've tested this on iOS, Catalyst, Android, and WinUI, and it only happens on WinUI.

Steps to Reproduce

  1. Run the included project
  2. Click on "Set EmptyView to Null"

In the output logs, you'll see that the view was set to StackLayout, then set to null. But the view is still on screen and not removed.

Link to public reproduction project repository

https://github.com/drasticactions/MauiRepros/tree/main/Finish

Version with bug

7.0.101

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewCollectionView, CarouselView, IndicatorViewp/2Work that is important, but is currently not scheduled for releasepartner/hot-reload-xamlIssues impacting XAML Hot Reload experiencespartner/hot-reload-xaml-full-page-fixedIssues with XAML incremental hot reload that are fixed after a full page hot reloadpartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/windowss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions