Skip to content

[XSG] Attributes on property element syntax not handled correctly #33868

@StephaneDelcroix

Description

@StephaneDelcroix

Description

XAML Source Generator (XSG) does not correctly handle attributes placed directly on property element syntax (e.g., <TypeName.Property Attribute="value">).

This is invalid XAML syntax - property elements should contain child elements, not have attributes. The runtime inflator was incorrectly permissive and allowed it.

Decision

XSG should emit a clear error explaining this is invalid XAML syntax. We should not allow this.

Reproduction

<foldable:TwoPaneView x:Name="twoPaneView">
    <foldable:TwoPaneView.Pane1
        BackgroundColor="#dddddd">
        <Frame BorderColor="Red">
            <!-- content -->
        </Frame>
    </foldable:TwoPaneView.Pane1>
</foldable:TwoPaneView>

The BackgroundColor attribute on <foldable:TwoPaneView.Pane1> is invalid - attributes cannot be placed on property elements.

Expected Behavior

XSG should emit a clear error such as:

"Attributes are not allowed on property element 'TwoPaneView.Pane1'. Use child elements instead."

Affected File

src/Controls/samples/Controls.Sample/Pages/Others/TwoPaneViewPage.xaml

Workaround

Fix the XAML to use valid syntax (move BackgroundColor to the child element or use a different approach).

Context

Discovered while enabling XSG on more projects in #33524.

Metadata

Metadata

Labels

s/triagedIssue has been reviewed

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions