Skip to content

Remove XamlControlsResourcesV2 rewrite#22940

Open
MartinZikmund wants to merge 4 commits intomasterfrom
dev/mazi/avoid-xamlresources-rewrite
Open

Remove XamlControlsResourcesV2 rewrite#22940
MartinZikmund wants to merge 4 commits intomasterfrom
dev/mazi/avoid-xamlresources-rewrite

Conversation

@MartinZikmund
Copy link
Copy Markdown
Member

GitHub Issue: Closes #22824

PR Type:

🔄 Refactoring (no functional changes, no api changes)

What is the current behavior? 🤔

The XAML source generator in XamlFileGenerator.BuildTypedResourceDictionary() special-cases XamlControlsResources and rewrites it to XamlControlsResourcesV2 in generated C#:

if (type.GetFullyQualifiedTypeExcludingGlobal().Equals("Microsoft.UI.Xaml.Controls.XamlControlsResources", ...))
{
    // Generates: new global::Microsoft.UI.Xaml.Controls.XamlControlsResourcesV2()
}

This was needed when V1/V2 coexisted. V1 is gone; XamlControlsResources already forces Version2 and initializes both FluentTheme and FluentTheme.v2 static resources.

What is the new behavior? 🚀

  • The special-case rewrite is removed. XamlControlsResources references in XAML now generate new XamlControlsResources() like any other typed ResourceDictionary subclass.
  • XamlControlsResourcesV2 is kept as-is for backward compatibility with existing C# references.

PR Checklist ✅

Please check if your PR fulfills the following requirements:

Other information ℹ️

No functional change — XamlControlsResources constructor already calls Uno.UI.FluentTheme.v2.GlobalStaticResources.Initialize() / RegisterDefaultStyles() / RegisterResourceDictionariesBySource() in its UpdateSource() path, identical to what XamlControlsResourcesV2 does.

Copilot AI review requested due to automatic review settings April 1, 2026 12:36
@github-actions github-actions bot added the area/code-generation Categorizes an issue or PR as relevant to code generation label Apr 1, 2026
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ MartinZikmund
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 3 commits April 1, 2026 14:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 removes a legacy special-case in the XAML source generator that rewrote Microsoft.UI.Xaml.Controls.XamlControlsResources to XamlControlsResourcesV2, aligning generated code with the actual type referenced in XAML now that V1 is no longer supported.

Changes:

  • Removed the XamlControlsResources -> XamlControlsResourcesV2 rewrite in XamlFileGenerator.BuildTypedResourceDictionary().
  • Added a generator test covering typed XamlControlsResources usage in a merged dictionary.
  • Updated/added expected generated output snapshots for the new test case.

Reviewed changes

Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs Drops the hard-coded rewrite and always emits new <typed ResourceDictionary>() for typed dictionaries.
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_ResourceDictionary.cs Adds a regression test ensuring XamlControlsResources is instantiated (not rewritten).
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/Given_ResourceDictionary/WhTyXaCoReReDi/XamlCodeGenerator_MyResourceDictionary_92716e07ff456818f6d4125e055d4d57.cs Snapshot: verifies emitted new global::Microsoft.UI.Xaml.Controls.XamlControlsResources() in merged dictionaries.
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/Given_ResourceDictionary/WhTyXaCoReReDi/XamlCodeGenerator_GlobalStaticResources.cs Snapshot: expected generated GlobalStaticResources for the new test case.
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/Given_ResourceDictionary/WhTyXaCoReReDi/XamlCodeGenerator_LocalizationResources.cs Snapshot: expected localization metadata output for the new test case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@unodevops
Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22940/wasm-skia-net9/index.html

@unodevops
Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22940/wasm-skia-net9/index.html

@unodevops
Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 205842 has failed on Uno.UI - CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/code-generation Categorizes an issue or PR as relevant to code generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid XamlControlsResourcesV2 rewrite

5 participants