-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[net11.0] Use ElementHandlerAttribute instead of DI for built-in visual elements #29952
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
base: net11.0
Are you sure you want to change the base?
[net11.0] Use ElementHandlerAttribute instead of DI for built-in visual elements #29952
Conversation
There was a problem hiding this 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 transitions built-in controls from DI registration to using [ElementHandler] attributes, introduces IElementHandlerWithAndroidContext<T> for Android renderers, and adds a new MSBuild property to toggle CSS support.
- Apply
[ElementHandler]to core controls and cells instead of DI - Introduce
IElementHandlerWithAndroidContext<T>andCreateHandler(Context)on Android renderers - Add
MauiCssEnabledMSBuild property and corresponding runtime host configuration
Reviewed Changes
Copilot reviewed 120 out of 120 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Controls/src/Core/ContentPage/ContentPage.Mapper.cs | Added static ctor calling RemapForControls and VisualElement.RemapIfNeeded |
| src/Controls/src/Core/Compatibility/Handlers/TableView/Android/TableViewRenderer.cs | Implemented IElementHandlerWithAndroidContext<TableViewRenderer> and CreateHandler |
| src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewRenderer.cs | Implemented IElementHandlerWithAndroidContext<ListViewRenderer> and CreateHandler |
| src/Controls/src/Core/Compatibility/Handlers/Android/FrameRenderer.cs | Implemented IElementHandlerWithAndroidContext<FrameRenderer> and CreateHandler |
| src/Controls/src/Core/Cells/*.cs | Added [ElementHandler<...>] attributes for compatibility cell renderers |
| src/Controls/src/Core/Button/Button.cs | Added [ElementHandler<ButtonHandler>] |
| src/Controls/src/Core//.Mapper.cs | Added static ctors calling RemapForControls / RemapIfNeeded |
| src/Controls/src/Build.Tasks/nuget/.../Microsoft.Maui.Controls.targets | Added MauiCssEnabled property and runtime host configuration option |
| src/Compatibility/Core/src/{iOS,Android}/Platform.cs | Updated GetHandler calls to pass MauiContext |
Comments suppressed due to low confidence (1)
src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets:240
- Added the
MauiCssEnabledbuild property but no corresponding public documentation under/docs/; please update the XML docs to describe this new feature.
<MauiCssEnabled Condition="'$(MauiCssEnabled)' == '' and '@(MauiCss->Count())' == '0'">false</MauiCssEnabled>
| { | ||
| #pragma warning disable CS0618 // Type or member is obsolete | ||
| public class TableViewRenderer : ViewRenderer<TableView, AListView> | ||
| public class TableViewRenderer : ViewRenderer<TableView, AListView>, IElementHandlerWithAndroidContext<TableViewRenderer> |
Copilot
AI
Jun 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing IElementHandlerWithAndroidContext introduces a new public interface on this renderer, which is a breaking API change; please assess version impact.
| { | ||
| #pragma warning disable CS0618 // Type or member is obsolete | ||
| public class ListViewRenderer : ViewRenderer<ListView, AListView> | ||
| public class ListViewRenderer : ViewRenderer<ListView, AListView>, IElementHandlerWithAndroidContext<ListViewRenderer> |
Copilot
AI
Jun 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing IElementHandlerWithAndroidContext introduces a new public interface on this renderer, which is a breaking API change; please assess version impact.
| { | ||
| [Obsolete("Frame is obsolete as of .NET 9. Please use Border instead.")] | ||
| public class FrameRenderer : CardView, IPlatformViewHandler | ||
| public class FrameRenderer : CardView, IPlatformViewHandler, IElementHandlerWithAndroidContext<FrameRenderer> |
Copilot
AI
Jun 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing IElementHandlerWithAndroidContext introduces a new public interface on this renderer, which is a breaking API change; please assess version impact.
|
/azp run |
|
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
33afe18 to
c49e57e
Compare
|
@copilot there are merge conflicts in this branch. please resolve them. When you're done, write summary of what this PR does and what functionality is missing to fully convert the "old" way of implementing handlers to the "new" way. |
|
@simonrozsival I've opened a new pull request, #32861, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@copilot oops, try now! |
|
@simonrozsival I've opened a new pull request, #32862, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@copilot there are several errors popping up:
Fix them and make sure the product can be built. |
|
@simonrozsival I've opened a new pull request, #32933, to work on those changes. Once the pull request is ready, I'll request review from you. |
…ameRenderer and TableViewRenderer
…al elements (#32862) * Initial plan * Resolve merge conflicts from main branch Co-authored-by: simonrozsival <[email protected]> * Change ElementHandlerAttribute from generic to Type parameter Co-authored-by: simonrozsival <[email protected]> * Remove unnecessary suppression details and simplify Co-authored-by: simonrozsival <[email protected]> * Improve ElementHandelrAttribute error handling * Fix ElementHandlerAttribute --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: simonrozsival <[email protected]> Co-authored-by: Simon Rozsival <[email protected]>
…onflicts (#32933) * Initial plan * Fix build errors: fully qualify ShellHandler/ShellItemHandler and resolve merge conflicts Co-authored-by: simonrozsival <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: simonrozsival <[email protected]>
…ement (#33138) * Initial plan * Fix build failures in HostBuilderHandlerTests by adding IMauiContext parameter Co-authored-by: simonrozsival <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: simonrozsival <[email protected]>
…Enabled to RuntimeFeature
d4f1219 to
820c96d
Compare
6ced46a to
fd782a0
Compare
fd782a0 to
7c7d0f8
Compare
This is a follow-up to #28357
I modified all built-in controls to use
[ElementHandler<THandler>]instead of DI. This allowed me to remove all ofAppHostBuilderExtensions.AddControlsHandlers().I needed to add a new
[ElementHandlerWithAndroidContext<THandler>]+ interfaceIElementHandlerWithAndroidContext<THandler>which allows us to create handlers that need injecting the Android context in the constructor. This works perfectly well for our internal use, but I'm not sure if this will be an acceptable API to expose to our customers. This attribute is currently needed for 3 compatibility handlers:FrameRenderer(deprecated in .NET 9),ListViewRenderer(deprecated in .NET 10),TableViewRenderer(deprecated in .NET 10). I might revisit this before I mark this PR as ready for review.It was necessary to make changes to
MauiHandlerFactoryto correctly resolve handlers when they were explicitly registered via DI. This is tricky because our handler resolution algorithm is pretty complicated. I wonder if we should revisit and simplify this part (it's not clear to me how much of a breaking change this could be for our customers).TODO: