Repository navigation
fix: restore XamlScope in ElementStub.Materialize for StaticResource resolution - #23089
Merged
Merged
Conversation
…resolution Fixes #23088 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes {StaticResource} resolution for lazily materialized x:Load="False" subtrees by capturing the current XamlScope when ElementStub is created during parsing and restoring it during MaterializeInner(), matching the FrameworkTemplate behavior. It also adds a runtime regression test to ensure no ResourceBinding fallback is created after materialization.
Changes:
- Capture
ResourceResolver.CurrentScopeinElementStubconstruction and restore it viaPushNewScope/PopScopeduring materialization. - Add a runtime regression test verifying eager
{StaticResource}resolution forx:Load="False". - Add a small XAML control used by the new regression test.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Uno.UI/UI/Xaml/ElementStub.cs | Capture/restore XamlScope around stub materialization to enable correct static resource resolution. |
| src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_xLoad.cs | Add regression test ensuring no ResourceBinding is created after materializing an x:Load="False" element with {StaticResource}. |
| src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/xLoad_StaticResource.xaml.cs | New test control code-behind for the regression scenario. |
| src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/xLoad_StaticResource.xaml | New test XAML defining a lazy ContentControl using {StaticResource}. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MartinZikmund
approved these changes
Apr 21, 2026
Contributor
Author
|
argh... |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub Issue: closes #23088, re: unoplatform/kahua-private#403
PR Type:
What is the current behavior? 🤔
When an element has
x:Load="False", it is replaced by anElementStubplaceholder at parse time. When the element is later materialized,ResourceResolver.CurrentScopeis empty (the parse-time scope has already been popped), so{StaticResource}lookups inside the lazily-created subtree fail to find resources in ancestor elements. This causes spurious warning logs as the resolution falls back to a deferredResourceBinding.What is the new behavior? 🚀
ElementStubnow capturesResourceResolver.CurrentScopeat construction time (during XAML parsing), mirroring the existing pattern inFrameworkTemplate. WhenMaterializeInner()is called, the captured scope is pushed before the content builder runs and popped in thefinallyblock. This allows{StaticResource}lookups inside lazily-materialized subtrees to correctly walk the ancestor resource chain and resolve eagerly without creating spuriousResourceBindingdeferred bindings.PR Checklist ✅
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information ℹ️
The fix follows the exact same scope save/restore pattern already established in
FrameworkTemplate.cs(lines 109, 189, 223). The new runtime testGiven_xLoad.When_xLoad_False_StaticResource_Resolvesverifies that after materialization,ContentControl.ContentPropertyhas noResourceBinding(i.e., it resolved statically) and the value equals"RESOLVED".