Skip to content

Remove .NET MAUI internals usage#452

Merged
TheCodeTraveler merged 38 commits into
mainfrom
jfversluis-fix-maui-internals
Jul 22, 2026
Merged

Remove .NET MAUI internals usage#452
TheCodeTraveler merged 38 commits into
mainfrom
jfversluis-fix-maui-internals

Conversation

@jfversluis

@jfversluis jfversluis commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace MAUI internal FontElement/TextElement/ImageElement/PlaceholderElement/PaddingElement usage with public concrete BindableProperty mappings.
  • Narrow dynamic-resource helpers to public Element APIs instead of internal IDynamicResourceHandler/BindableObject internals.
  • Replace the custom internal TypedBindingBase-derived implementation with public Binding-based typed binding behavior.
  • Add typed-binding regression coverage for read-only/default TwoWay targets, setter write-back, OneWayToSource initial and late BindingContext pushes, object-valued paths, Binding.DoNothing, invalid convert-back values, and captured-value binding contexts.

Validation

  • Product-code internals scan: no matches for Microsoft.Maui.Controls.Internals, .Internals, FontElement, TextElement, ImageElement, PlaceholderElement, PaddingElement, IDynamicResourceHandler, TypedBindingBase, BindingExpression, SetValueCore, GetContext, ApplyCore, UnapplyCore, GetRealizedMode, BindingExpressionPart, BindingFlags.NonPublic, GetMethod/GetField/GetProperty in src/CommunityToolkit.Maui.Markup.
  • Unit tests: 402/402 passed via the NUnit executable runner.
  • Sample app: net10.0-windows10.0.19041.0 Debug build succeeded.
  • Pack: CommunityToolkit.Maui.Markup.99.0.4-internalsfix.nupkg built locally.
  • MAUI 11 PR #34070 smoke app: built with Microsoft.Maui.Controls 11.0.0-ci.pr34070.6.26324.9 and launched on Windows; app stayed running after startup with no FieldAccessException/startup crash.

Notes

  • TypedBinding.cs was removed because public BindingBase cannot be subclassed equivalently outside MAUI internals. The replacement preserves common path binding behavior and explicit setter write-back using public APIs.
  • Dynamic-resource helpers now require Element, matching the public MAUI dynamic-resource API surface.

Updated Documentation

The CommunityToolkit.Maui.Markup docs have been updated accordingly: MicrosoftDocs/CommunityToolkit#652

Copilot AI review requested due to automatic review settings June 24, 2026 16:43

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 removes reliance on .NET MAUI internal APIs from CommunityToolkit.Maui.Markup by replacing internal element/property access and custom internal binding infrastructure with public BindableProperty mappings and public Binding-based typed binding behavior, along with expanded regression tests.

Changes:

  • Replaced uses of MAUI internals (e.g., FontElement/TextElement/PaddingElement, internal dynamic resource handlers, and TypedBindingBase-derived typed binding) with public BindableProperty access and Binding/converters.
  • Added BindablePropertyHelpers to map supported controls to their public BindableProperty equivalents.
  • Updated/expanded unit tests to validate the new typed-binding behavior and updated property expectations.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/CommunityToolkit.Maui.Markup/TypedGesturesExtensions.cs Updates member-name extraction to avoid treating captured values as bindable paths for typed gesture bindings.
src/CommunityToolkit.Maui.Markup/TypedBindingsExtensions.Handlers.cs Introduces SetTypedBinding implementation using public Binding plus manual source write-back and handler tracking.
src/CommunityToolkit.Maui.Markup/TypedBindingExtensions.cs Switches expression-based typed binding to compute public binding paths (or captured-value fallback) and delegates to SetTypedBinding.
src/CommunityToolkit.Maui.Markup/TypedBinding.cs Removes internal TypedBindingBase-based implementation that depended on MAUI internals.
src/CommunityToolkit.Maui.Markup/PlaceholderExtensions.cs Replaces internal placeholder properties with public property mapping via helpers.
src/CommunityToolkit.Maui.Markup/ImageExtensions.cs Replaces internal image element properties with public property mapping via helpers.
src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Replaces internal font/text/padding properties and narrows dynamic-resource removal to Element.
src/CommunityToolkit.Maui.Markup/DynamicResourceHandlerExtensions.cs Narrows dynamic-resource helpers to public Element API surface.
src/CommunityToolkit.Maui.Markup/BindablePropertyHelpers.cs Adds helper methods that map supported control types to their public BindableProperty equivalents.
src/CommunityToolkit.Maui.Markup.UnitTests/BindingHelpers.cs Updates test reflection helpers to avoid MAUI internal types while still validating bindings.
src/CommunityToolkit.Maui.Markup.UnitTests/TypedBindingExtensionsTests.cs Adds/updates typed-binding regression tests for captured values, OneWayToSource push behavior, and write-back edge cases.
src/CommunityToolkit.Maui.Markup.UnitTests/GesturesExtensionsTests.cs Updates expectations for typed gesture binding modes under the new binding approach.
src/CommunityToolkit.Maui.Markup.UnitTests/TextTests.cs Updates expected BindableProperty references from internal element properties to public control properties.
src/CommunityToolkit.Maui.Markup.UnitTests/ElementExtensionsTests.cs Updates font-related expected properties to public control properties.
src/CommunityToolkit.Maui.Markup.UnitTests/PaddingElementExtensionsTests.cs Updates padding tests to use helper-mapped public padding properties.
src/CommunityToolkit.Maui.Markup.UnitTests/PaceholderExtensionsTests.cs Updates placeholder tests to use public placeholder properties.
src/CommunityToolkit.Maui.Markup.UnitTests/ImageExtensionTests.cs Updates image tests to use public image bindable properties.
src/CommunityToolkit.Maui.Markup.UnitTests/Mocks/MockApplication.cs Removes obsolete internal system-resource provider registration.
src/CommunityToolkit.Maui.Markup.UnitTests/UnitExpressionSearch.cs Removes test helper that depended on MAUI internals.
src/CommunityToolkit.Maui.Markup.UnitTests/Mocks/MockResourcesProvider.cs Removes obsolete internal system resource provider implementation.

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

Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Copilot AI review requested due to automatic review settings June 25, 2026 10:16
@jfversluis
jfversluis force-pushed the jfversluis-fix-maui-internals branch from 63480f5 to 407abc2 Compare June 25, 2026 10:18

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

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

Copilot AI review requested due to automatic review settings June 25, 2026 10:34

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

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

Copilot AI review requested due to automatic review settings June 25, 2026 11:34

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

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Copilot AI review requested due to automatic review settings June 30, 2026 07:36
@jfversluis
jfversluis force-pushed the jfversluis-fix-maui-internals branch from 8960a71 to 06644aa Compare June 30, 2026 07:36

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

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

Comment thread src/CommunityToolkit.Maui.Markup/TypedBindingsExtensions.Handlers.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
@jfversluis
jfversluis force-pushed the jfversluis-fix-maui-internals branch from 06644aa to 2cc6860 Compare July 7, 2026 13:00
@jfversluis

Copy link
Copy Markdown
Member Author

@TheCodeTraveler this PR is now rebased on latest main and remains green locally. Could you please prioritize the final review/merge sooner rather than later? We are getting close to merging the .NET MAUI 11 change that removes the internals access this PR fixes for Maui.Markup.

Copilot AI review requested due to automatic review settings July 16, 2026 18:58
@jfversluis
jfversluis force-pushed the jfversluis-fix-maui-internals branch from 2cc6860 to 7f2cb79 Compare July 16, 2026 18:58

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.

Review details

  • Files reviewed: 21/21 changed files
  • Comments generated: 4
  • Review effort level: Low

Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Copilot AI review requested due to automatic review settings July 16, 2026 19:12
@jfversluis
jfversluis force-pushed the jfversluis-fix-maui-internals branch from 7f2cb79 to f51d60f Compare July 16, 2026 19:12

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.

Review details

  • Files reviewed: 21/21 changed files
  • Comments generated: 3
  • Review effort level: Low

Comment thread src/CommunityToolkit.Maui.Markup/TypedBindingsExtensions.Handlers.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/BindablePropertyHelpers.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Copilot AI review requested due to automatic review settings July 16, 2026 19:30

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.

Review details

  • Files reviewed: 21/21 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread src/CommunityToolkit.Maui.Markup/ImageExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/PlaceholderExtensions.cs Outdated

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

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

Comment thread src/CommunityToolkit.Maui.Markup/TypedBindingsExtensions.Handlers.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/TypedBindingExtensions.cs Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 00:42
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0f444540-c7ce-4df3-beab-874778209fcb
Copilot stopped reviewing on behalf of jfversluis due to an error July 22, 2026 00:42

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.

Review details

  • Files reviewed: 22/22 changed files
  • Comments generated: 9
  • Review effort level: Low

Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs
Comment on lines +47 to +53
return currentExpression switch
{
ParameterExpression when members.Count > 0 => string.Join(".", members),
ConstantExpression when members.Count > 0 => null,
null when members.Count > 0 => null,
_ => throw CreateInvalidGetterException()
};
Comment thread src/CommunityToolkit.Maui.Markup/PlaceholderExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/PlaceholderExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/PlaceholderExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Comment thread src/CommunityToolkit.Maui.Markup/ElementExtensions.cs Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 01:12

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

Copilot reviewed 22 out of 22 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 22, 2026 16:31

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

Copilot reviewed 22 out of 22 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 22, 2026 18:08

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

Copilot reviewed 22 out of 22 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 22, 2026 20:51

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

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

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 22, 2026 22:19

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

Copilot reviewed 23 out of 23 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/CommunityToolkit.Maui.Markup/TypedBindingsExtensions.Handlers.cs:304

  • In SetTypedBinding.ApplyBinding, when path is null (captured-value binding), the GetterValueConverter already applies stringFormat / TargetNullValue / FallbackValue. Passing stringFormat into the Binding as well (and setting TargetNullValue/FallbackValue on the binding) can result in these being applied twice (e.g., "{0}%" becomes "0.5%%"). These binding-level options should only be set when using a real path and not using the converter-based handling.
					converterParameter,
					targetUpdateTracker is null ? stringFormat : null,
					source);

				if (targetUpdateTracker is null)

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.

Review details

  • Files reviewed: 23/23 changed files
  • Comments generated: 0 new
  • Review effort level: Low

@TheCodeTraveler TheCodeTraveler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks Gerald!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants