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

Add container lifecycle events to ItemsControl. #10685

Merged
merged 4 commits into from
Mar 17, 2023

Conversation

grokys
Copy link
Member

@grokys grokys commented Mar 16, 2023

What does the pull request do?

Before #9677 we had materialized/dematerialized events for item containers (even though the API was pretty confused). They were removed as part of #9677 mostly to see if anyone missed them, but with the anticipation that we'd probably want to add them back. Turns out that they were being using on 0.10.x and people do miss them ;)

This PR adds them back in a slightly more sane form. The events follow the pattern used by ItemsRepeater, meaning that we have 3 new events on ItemsControl:

  • ContainerPrepared is raised each time a container is prepared for use. The prepared container might be newly created or an existing container that is being re-used.
  • ContainerIndexChanged is raised for each realized container where the index for the item it represents has changed. For example, when another item is added or removed in the data source, the index for items that come after in the ordering will be impacted.
  • ContainerClearing s raised immediately each time an container is cleared, such as when it falls outside the range of realized items or the corresponding item is removed

Seems we weren't calling `ClearItemContainer` for `ItemIsOwnContainer` items in `PanelContainerGenerator`. Fixed that too.
And fix index error in VirtualizingStackPanel.
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0031943-beta. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]

@danipen
Copy link

danipen commented Mar 16, 2023

Thanks for bringing back this again!

Is there a 1:1 equivalence between old Materialized/Recycled/Dematerialized events and the new ones?

@grokys
Copy link
Member Author

grokys commented Mar 17, 2023

Is there a 1:1 equivalence between old Materialized/Recycled/Dematerialized events and the new ones?

Not 1:1 but they're reasonably close:

Materialized = ContainerPrepared
Dematerialized = ContainerCleared
Recycled = this one was badly implemented in the previous version, and its meaning was overloaded, but the closest might be ContainerIndexChanged

Think of it like this:

ContainerPrepared: the container is now displaying this item
ContainerCleared: the container is no longer displaying an item
ContainerIndexChanged: the container's item has changed index due to an insert/remove etc in the items source, but it's still displaying an item, and the item is still the same

@danwalmsley danwalmsley added this pull request to the merge queue Mar 17, 2023
Merged via the queue into master with commit 3f46326 Mar 17, 2023
@danwalmsley danwalmsley deleted the feature/9497-container-lifecycle-events branch March 17, 2023 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants