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

Do not defer resources with name registration on them #14703

Merged
merged 6 commits into from
Mar 1, 2024

Conversation

maxkatz6
Copy link
Member

What does the pull request do?

<Window.Resources>
	<Panel Name="MyPanel" x:Key="MyPanel"/>
</Window.Resources>

With this ^ code XamlX compiler currently would defer initialization of MyPanel resource until it's resolved first time by its key.
Unfortunately, NameScope registration is active only while Window itself is initializing, and on top of that deferred resources always use nested child name scopes. Resulting in a situation, when MyPanel resource will never get into Window namescope.

One possible solution would be to extend deferred initialization to our name scopes, but I don't see any benefits of spending time on that. As named controls are more often than less accessed at some point, and there is no point to defer something that will be executed anyway. While most of our theme resources might not be used ever during application lifetime.

So, simpler and more straightforward solution is to disable deferring, if resource is candidate to be registered in the namescope.

Note: Avalonia still doesn't support any type of objects registered in the namescope, but only these with INamed interface on them. See: #6276. But stuff like Panel should be fine.

Checklist

Fixed issues

Fixes #14693

@avaloniaui-bot
Copy link

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

@avaloniaui-bot
Copy link

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

@avaloniaui-bot
Copy link

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

@maxkatz6 maxkatz6 merged commit aeafbf9 into master Mar 1, 2024
7 checks passed
@maxkatz6 maxkatz6 deleted the do-not-defer-named-resources branch March 1, 2024 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fields created for named resources have no values assigned
3 participants