maui
maui copied to clipboard
Inheriting Visual States
Description of Change
Visual states from parent types aren't being applied to derived types.
I have a button that when clicked switches between a Normal and a Custom state:
VisualStateManager.GoToState(button, !isNormal ? "Custom" : "Normal");
Everything works as expected when both states are defined in the same VisualStateGroup:
<Style TargetType="Button">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState Name="Normal">
<VisualState.Setters>
<Setter Property="TextColor" Value="White" />
<Setter Property="BackgroundColor" Value="Black" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Custom">
<VisualState.Setters>
<Setter Property="TextColor" Value="Red" />
<Setter Property="BackgroundColor" Value="Green" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
The issue occurs when one of the visual states is defined in the parent Style. In that context the Custom style is ignored - the same happens when the visual state is defined in the global styles.
<Style TargetType="Button" x:Key="parentStyle">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState Name="Custom">
<VisualState.Setters>
<Setter Property="TextColor" Value="Red" />
<Setter Property="BackgroundColor" Value="Green" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
<Style TargetType="Button" BasedOn="{StaticResource parentStyle}">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState Name="Normal">
<VisualState.Setters>
<Setter Property="TextColor" Value="White" />
<Setter Property="BackgroundColor" Value="Black" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
This PR is supposed to fix it by adding the visual state that has not been defined in the derived style from the parent style to the derived style
| Before | After |
|---|---|
Hey there @kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.
@kubaflo Your work seems to be, to some degree, related to #19812. Any feedback would be awesome.
/azp-run
/azp run
Azure Pipelines successfully started running 3 pipeline(s).