Skip to content

fix: restore XamlScope in ElementStub.Materialize for StaticResource resolution - #23089

Merged
Xiaoy312 merged 1 commit into
masterfrom
dev/xygu/20260420/elementstud-xamlscope
Apr 21, 2026
Merged

Xiaoy312 merged 1 commit into
masterfrom
dev/xygu/20260420/elementstud-xamlscope

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #23088, re: unoplatform/kahua-private#403

PR Type:

  • 🐞 Bugfix

What is the current behavior? 🤔

When an element has x:Load="False", it is replaced by an ElementStub placeholder at parse time. When the element is later materialized, ResourceResolver.CurrentScope is 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 deferred ResourceBinding.

What is the new behavior? 🚀

ElementStub now captures ResourceResolver.CurrentScope at construction time (during XAML parsing), mirroring the existing pattern in FrameworkTemplate. When MaterializeInner() is called, the captured scope is pushed before the content builder runs and popped in the finally block. This allows {StaticResource} lookups inside lazily-materialized subtrees to correctly walk the ancestor resource chain and resolve eagerly without creating spurious ResourceBinding deferred bindings.

PR Checklist ✅

Please check if your PR fulfills the following requirements:

Other information ℹ️

The fix follows the exact same scope save/restore pattern already established in FrameworkTemplate.cs (lines 109, 189, 223). The new runtime test Given_xLoad.When_xLoad_False_StaticResource_Resolves verifies that after materialization, ContentControl.ContentProperty has no ResourceBinding (i.e., it resolved statically) and the value equals "RESOLVED".

Copilot AI review requested due to automatic review settings April 20, 2026 21:43
@Xiaoy312
Xiaoy312 enabled auto-merge April 20, 2026 21:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.CurrentScope in ElementStub construction and restore it via PushNewScope / PopScope during materialization.
  • Add a runtime regression test verifying eager {StaticResource} resolution for x: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.

Comment thread src/Uno.UI/UI/Xaml/ElementStub.cs Resolved
@Xiaoy312
Xiaoy312 merged commit e9888f2 into master Apr 21, 2026
46 checks passed
@Xiaoy312
Xiaoy312 deleted the dev/xygu/20260420/elementstud-xamlscope branch April 21, 2026 17:47
@Xiaoy312

Copy link
Copy Markdown
Contributor Author

argh...

@Xiaoy312 Xiaoy312 mentioned this pull request Apr 21, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lazily loaded control (x:Load=false) is missing XamlScope for its resource resolution

3 participants