Repository navigation
[XSG] Fix Style setter with content syntax in SourceGen - #32890
Merged
Merged
Conversation
When using content property syntax for Setter values like:
<Setter Property="AbsoluteLayout.LayoutBounds">10,10,20,20</Setter>
The source generator was producing invalid code:
.Value = "10,10,20,20";
var setter = new Setter {...};
The fix adds the content property name to SkipProperties when the value
is specified as a collection item, preventing SetPropertiesVisitor from
trying to process it separately with an empty variable name.
Fixes #32879
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
StephaneDelcroix
previously approved these changes
Nov 27, 2025
Copilot
AI
changed the title
[WIP] Fix style with setter on AbsoluteLayout.LayoutBounds
Fix Style setter with attached property content syntax in SourceGen
Nov 27, 2025
Member
|
@copilot Please add also a SourceGen test |
Added Maui32879Tests.cs with two tests: - StyleSetterWithAttachedPropertyContentSyntax: Tests the fixed issue where using content property syntax like <Setter Property="...">value</Setter> previously generated invalid C# code - StyleSetterWithAttachedPropertyAttributeSyntax: Tests that the normal attribute syntax still works correctly Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Contributor
Author
simonrozsival
left a comment
Member
There was a problem hiding this comment.
@copilot address my comments please
- Remove Console.WriteLine debug statements - Simplify asserts inline with result.Diagnostics Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Transform Maui32879Tests to use the snapshot test pattern to clearly show the expected generated C# code. This makes it easy to verify that the Setter is properly generated inline without the invalid `.Value = ...` dead code line. Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
simonrozsival
approved these changes
Nov 27, 2025
Member
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the XAML SourceGen where using content property syntax for Setter.Value (e.g., <Setter Property="...">10,10,20,20</Setter>) generated invalid C# code. The bug occurred when the inline initialization optimization for known value providers (like Setter) marked explicit properties to skip but missed the content property when it was specified as a collection item.
Key changes:
- Added logic to skip the content property when it's specified as a collection item for types that can be inlined (known value providers)
- Added comprehensive test coverage in both Xaml.UnitTests and SourceGen.UnitTests to verify the fix
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Controls/src/SourceGen/Visitors/CreateValuesVisitor.cs | Added logic to detect and skip content properties specified as collection items when handling known value providers that can be inlined |
| src/Controls/tests/Xaml.UnitTests/Issues/Maui32879.xaml | XAML test file demonstrating the Style setter with attached property using content property syntax |
| src/Controls/tests/Xaml.UnitTests/Issues/Maui32879.xaml.cs | Runtime test that verifies the fix works across all XAML inflators (Runtime, XamlC, SourceGen) |
| src/Controls/tests/SourceGen.UnitTests/Maui32879Tests.cs | Snapshot test validating the source generator produces valid C# code with the expected output |
StephaneDelcroix
approved these changes
Nov 27, 2025
StephaneDelcroix
enabled auto-merge (squash)
November 28, 2025 07:51
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 of Change
XAML SourceGen produces invalid C# when
Setteruses content property syntax:Generated code was:
Root cause: When
Settervalue is a collection item (content property syntax) rather than an attribute, the inline initialization optimization marked properties to skip but missed the content property.SetPropertiesVisitorthen processed it with the placeholder empty variable name.Fix: In
CreateValuesVisitor, when handling known value providers that can be inlined, also add the content property name toSkipPropertieswhen the value comes from a collection item.Tests added:
Maui32879.xaml/.xaml.cs- Xaml.UnitTests to verify the fix works across all XAML inflators (Runtime, XamlC, SourceGen)Maui32879Tests.cs- SourceGen.UnitTests snapshot test that validates the source generator produces valid C# code, with the expected generated output clearly shown in the testIssues Fixed
Fixes #32879