Skip to content

Add ItemsControl.PreparingContainer event #14153

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

Merged

Conversation

TomEdwardsEnscape
Copy link
Contributor

Add a new event that is raised before an item container is prepared for use.

What is the current behavior?

Currently it is not possible to intercept item container preparation. There is only the ContainerPrepared event, which is raised after the fact.

This causes issues in our product, which sometimes needs to do DI work before constructing item container templates.

Breaking changes

None

Obsoletions / Deprecations

None

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0043400-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 requested a review from grokys January 10, 2024 02:18
@TomEdwardsEnscape
Copy link
Contributor Author

Actually, while this change does fix the issue we were having, an even better solution for us would be to hook into template construction (to record the DI context) and template instantiation (to restore the DI context). We can do this by creating our own template types derived from the normal ones. Then we can get the behaviour we need at any time, without an ItemsControl.

I'll leave this PR open, as IMO it still makes sense to add the event for general purpose use.

@MrJul MrJul removed the request for review from grokys October 10, 2024 12:09
Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is accepted: it's low risk, is a counterpart of ContainerPrepared, has no performance impact without any listeners, and can help consumers needing it.

Thanks!

@MrJul MrJul added this pull request to the merge queue Oct 10, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 10, 2024
@MrJul MrJul merged commit 353ad7d into AvaloniaUI:master Oct 10, 2024
@TomEdwardsEnscape TomEdwardsEnscape deleted the feature/itemscontrol-preparing-container branch April 4, 2025 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants