-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
area-toolingXAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, DebuggingXAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debuggings/triagedIssue has been reviewedIssue has been reviewed
Description
Description
When using VisualStateManager.VisualStateGroups in XAML with the source generator, the app throws InvalidOperationException: VisualStateGroup Names must be unique at first startup.
Expected Behavior
The page should load without errors — each VisualStateGroup name appears only once in the XAML.
Actual Behavior
System.InvalidOperationException: VisualStateGroup Names must be unique
at Microsoft.Maui.Controls.VisualStateManager.Validate(...)
Steps to Reproduce
- Create a page with a Button that has VisualStateManager.VisualStateGroups:
<Button Text="Press me">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="White" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Pressed">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightGray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Button>- Build and run — crashes at startup
Root Cause
The SG-generated InitializeComponent processes the VisualStateManager.VisualStateGroups collection-type attached property. During processing, the VisualStateGroupList validation callback fires and finds a duplicate "CommonStates" name — likely because the group is added to the collection during construction and then the list is assigned to the property, triggering re-validation against a pre-existing entry.
Affected Area
- XAML Source Generator (SourceGen)
SetPropertiesVisitorhandling of collection-type attached properties with named items
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-toolingXAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, DebuggingXAML & C# Hot Reload, XAML Editor, Live Visual Tree, Live Preview, Debuggings/triagedIssue has been reviewedIssue has been reviewed