Skip to content

[XSG] Create AppThemeBinding using [UnsafeAccessor] in .NET 10#32728

Merged
StephaneDelcroix merged 3 commits intomainfrom
dev/srozsival/xsg-app-theme-binding-unsafe-accessors
Nov 19, 2025
Merged

[XSG] Create AppThemeBinding using [UnsafeAccessor] in .NET 10#32728
StephaneDelcroix merged 3 commits intomainfrom
dev/srozsival/xsg-app-theme-binding-unsafe-accessors

Conversation

@simonrozsival
Copy link
Member

Description of Change

AppThemeBinding class is not public in .NET 10, so the source-generated code that instantiated it was causing build errors. To work around that, we can use [UnsafeAccessor] with the new .NET 10 feature of [UnsafeAccessorType].

In .NET 11, this change should be (mostly) reverted once AppThemeBinding is public (incl. changes to PublicAPI.txt).

Issues Fixed

Fixes #32665
Supersedes #32678

@simonrozsival simonrozsival added this to the .NET 10.0 SR2 milestone Nov 19, 2025
Copilot AI review requested due to automatic review settings November 19, 2025 08:31
@simonrozsival simonrozsival added the xsg Xaml sourceGen label Nov 19, 2025
Copy link
Contributor

@StephaneDelcroix StephaneDelcroix left a comment

Choose a reason for hiding this comment

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

let's limit the API surface once we open this

Copy link
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 addresses build errors in .NET 10 where AppThemeBinding is not public by introducing helper methods that use [UnsafeAccessor] with the new [UnsafeAccessorType] attribute to access the internal class. The solution is conditional and will be mostly reverted in .NET 11 when AppThemeBinding becomes public.

Key changes:

  • Added AppThemeBindingHelpers class with conditional compilation for .NET 10 vs .NET 11
  • Updated source generation code to call helper methods instead of directly instantiating AppThemeBinding
  • Made AppThemeBinding conditionally public in .NET 11

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Controls/src/SourceGen/XamlGenerator.cs Generates AppThemeBindingHelpers class with UnsafeAccessor methods for .NET 10 and direct instantiation for .NET 11
src/Controls/src/SourceGen/KnownMarkups.cs Updates ProvideValueForAppThemeBindingExtension to generate calls to helper methods instead of object initializer syntax
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/AppThemeBinding.cs Updates test expectations to use new helper method calls
src/Controls/src/Core/AppThemeBinding.cs Adds conditional public modifier for .NET 11 with TODO comment

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Stephane Delcroix <stephane@delcroix.org>
@simonrozsival
Copy link
Member Author

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephaneDelcroix StephaneDelcroix merged commit 489c654 into main Nov 19, 2025
147 of 163 checks passed
@StephaneDelcroix StephaneDelcroix deleted the dev/srozsival/xsg-app-theme-binding-unsafe-accessors branch November 19, 2025 19:54
Copilot AI added a commit that referenced this pull request Dec 10, 2025
Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com>
Copilot AI added a commit that referenced this pull request Dec 10, 2025
Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com>
PureWeen added a commit that referenced this pull request Dec 10, 2025
PureWeen added a commit that referenced this pull request Dec 10, 2025
…eAccessor workaround for AppThemeBinding (#33101)

* Revert "[XSG] Create AppThemeBinding using [UnsafeAccessor] in .NET 10 (#32728)"

This reverts commit 489c654.

* disable appthemebinding

---------

Co-authored-by: Shane Neuville <shneuvil@microsoft.com>
Co-authored-by: Stephane Delcroix <stephane@delcroix.org>
@PureWeen PureWeen added the area-xaml XAML, CSS, Triggers, Behaviors label Dec 16, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-xaml XAML, CSS, Triggers, Behaviors xsg Xaml sourceGen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'AppThemeBinding' is inaccessible due to its protection level with XamlSourceGenerator on Version 10.0.20-ci.main.25566.1

4 participants