Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualizingStackPanel in a ListBox keep the DataContext on the ListBoxItem after the ClearItemContainer #16422

Open
Whiletru3 opened this issue Jul 23, 2024 · 0 comments
Labels

Comments

@Whiletru3
Copy link
Contributor

Describe the bug

The DataContext of the ListBoxItem is still set after a ClearItemContainer when the ListBox is virtualized

image

To Reproduce

In this repo, the sample VirtualizationImages has a Listbox Virtualized.
Zoom out to realize more elements, then zoom in. Then inspect the visual tree on the ListBoxItem cleared. the datacontext is still set on ListBoxItem but the ContentPresenter is empty

Expected behavior

The ListBoxItem Datacontext should be set to null on cleared items.

Be careful, the ContainerClearing event should be invoke before the ClearContainerForItemOverride to be able to work on the DataContext before clearing. Or you can add another event BeforeContainerClearing or something like this.

Current ItemsControl.ClearItemContainer :

        internal void ClearItemContainer(Control container)
        {
            ClearContainerForItemOverride(container);
            ContainerClearing?.Invoke(this, new(container));
        }

Avalonia version

11.0.11

OS

Windows, macOS

Additional context

No response

@Whiletru3 Whiletru3 added the bug label Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant