Remove .NET MAUI internals usage#452
Conversation
There was a problem hiding this comment.
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, andTypedBindingBase-derived typed binding) with publicBindablePropertyaccess andBinding/converters. - Added
BindablePropertyHelpersto map supported controls to their publicBindablePropertyequivalents. - 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.
63480f5 to
407abc2
Compare
8960a71 to
06644aa
Compare
06644aa to
2cc6860
Compare
|
@TheCodeTraveler this PR is now rebased on latest |
2cc6860 to
7f2cb79
Compare
7f2cb79 to
f51d60f
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0f444540-c7ce-4df3-beab-874778209fcb
| 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() | ||
| }; |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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, whenpathis null (captured-value binding), theGetterValueConverteralready appliesstringFormat/TargetNullValue/FallbackValue. PassingstringFormatinto theBindingas well (and settingTargetNullValue/FallbackValueon 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 realpathand not using the converter-based handling.
converterParameter,
targetUpdateTracker is null ? stringFormat : null,
source);
if (targetUpdateTracker is null)
Summary
Validation
Notes
TypedBinding.cswas removed because publicBindingBasecannot be subclassed equivalently outside MAUI internals. The replacement preserves common path binding behavior and explicit setter write-back using public APIs.Element, matching the public MAUI dynamic-resource API surface.Updated Documentation
The
CommunityToolkit.Maui.Markupdocs have been updated accordingly: MicrosoftDocs/CommunityToolkit#652