Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash in the XAML Source Generator (XSG) when Style.Setter targets a partial property decorated with the [BindableProperty] attribute from CommunityToolkit.MAUI. The issue occurs because source generators run in isolation - when XSG processes the XAML, it cannot see the BindableProperty field generated by another source generator running in parallel.
Changes:
- Made
GetBindablePropertyreturn nullable and updated all call sites to handle null gracefully - Added heuristic detection logic to identify properties with
[BindableProperty]attributes even when the generated field is not visible - Added fallback logic in
SetterValueProviderto construct BindableProperty references from type and property name - Comprehensive test coverage for both source generator and runtime scenarios
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| NodeSGExtensions.cs | Changed GetBindableProperty return type from IFieldSymbol to IFieldSymbol? to allow null returns |
| BindablePropertyConverter.cs | Added null check and fallback to "default" when BindableProperty is not found |
| SetterValueProvider.cs | Added heuristic fallback logic to detect [BindableProperty] attributes and construct BP references manually |
| ITypeSymbolExtensions.Maui.cs (not shown) | Added HasBindablePropertyHeuristic method to detect properties with recognized bindable property attributes |
| Maui33835.xaml | XAML test file with Style Setter targeting property with [BindableProperty] attribute |
| Maui33835.xaml.cs | Runtime test verifying Style Setter works correctly with all inflators |
| PartialPropertyInStyleSetterTests.cs | Source generator unit tests covering scenarios with/without visible BindableProperty field |
src/Controls/tests/SourceGen.UnitTests/InitializeComponent/PartialPropertyInStyleSetterTests.cs
Show resolved
Hide resolved
c3f3fda to
dc41b11
Compare
dc41b11 to
16e8f2e
Compare
StephaneDelcroix
approved these changes
Feb 11, 2026
…erated BindableProperty Fixes #33835 When a Style Setter uses a markup extension (e.g., {StaticResource}) on a property with [BindableProperty] attribute from CommunityToolkit.MAUI, the XSG couldn't find the BindableProperty field because it's generated by another source generator running in parallel. The markup extension case wasn't handled by the existing fix (#33562) because SetterValueProvider.CanProvideValue returns false for markup extensions, causing the Setter to go through the standard processing path via BindablePropertyConverter, which called GetBindableProperty() and crashed on the null result. Fix: - Make GetBindableProperty(ValueNode) return IFieldSymbol? (nullable) instead of throwing when BP field is not found - Add heuristic fallback in BindablePropertyConverter to detect [BindableProperty] attributes on properties, matching the approach already used in SetterValueProvider - Add tests for the markup extension scenario
16e8f2e to
cd46cc3
Compare
Member
Author
|
/azp run maui-pr-devicetests,maui-pr-uitests |
|
Azure Pipelines successfully started running 2 pipeline(s). |
This was referenced Feb 11, 2026
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Fixes #33835
This PR fixes a remaining gap in the XSG handling of source-generated bindable properties (from CommunityToolkit.MAUI
[BindableProperty]attribute) — specifically when markup extensions like{StaticResource}are used in Style Setters.Background
PR #33562 fixed Style Setters with simple literal values on source-generated bindable properties. However, when the Setter value uses a markup extension (e.g.,
{StaticResource TestColor}), a different code path is taken:SetterValueProvider.CanProvideValue()returnsfalsefor markup extensionsBindablePropertyConverterBindablePropertyConvertercallsGetBindableProperty()which returns null (field not visible to XSG)MAUIG1001: The method or operation is not implementedChanges
NodeSGExtensions.GetBindableProperty(ValueNode): Changed return type toIFieldSymbol?(nullable) — returns null instead of throwing when the bindable property field is not foundBindablePropertyConverter: Added heuristic fallback to detect[BindableProperty]attributes and construct the BP reference, matching the approach already used inSetterValueProviderReview Note
The Copilot reviewer comment about missing
TestColorresource was incorrect — the resource IS defined in both tests that reference it. The 3rd test uses a simple string value and correctly does not define it.