Skip to content

Styles based on other styles not applied #27202

@lucacivale

Description

@lucacivale

Description

With MAUI v8 we could create styles based on other styles

<Style x:Key="BaseLabel" TargetType="Label">
    <Setter Property="BackgroundColor" Value="Transparent" />
    <Setter Property="FontFamily" Value="OpenSansRegular" />
    <Setter Property="FontSize" Value="20" />
    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Disabled">
                    <VisualState.Setters>
                        <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray300}, Dark={StaticResource Gray600}}" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>

<Style BasedOn="{StaticResource BaseLabel}" TargetType="local:MyLabel">
    <Setter Property="TextColor" Value="Green" />
</Style>

<Style BasedOn="{StaticResource BaseLabel}" TargetType="local:MyLabel2">
    <Setter Property="TextColor" Value="Blue" />
</Style>
<VerticalStackLayout Padding="30,0" Spacing="25">
    <local:MyLabel Text="Label with derrived style with derrived disabled visual state" />
    <local:MyLabel2 Text="Label with derrived style with explicit disabled visual state" />
    <local:MyLabel IsEnabled="False" Text="Disabled label with derrived style with derrived disabled visual state" />
    <local:MyLabel2 IsEnabled="False" Text="Disabled label with derrived style with explicit disabled visual state" />
</VerticalStackLayout>

Image

This does not work with MAUI 9.0.30 anymore
Image

Steps to Reproduce

  1. Create custom control derived from label. No other customizations needed
  2. Create the styles as in Description described
  3. Create a new ContentPage with the VerticalStackLayout as in Description described.

Link to public reproduction project repository

No response

Version with bug

9.0.30 SR3

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.100 SR10

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

Set VisualStates explicit on derived styles.

<Style BasedOn="{StaticResource BaseLabel}" TargetType="local:MyLabel2">
    <Setter Property="TextColor" Value="Blue" />
    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Disabled">
                    <VisualState.Setters>
                        <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray300}, Dark={StaticResource Gray600}}" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>

Image

Relevant log output

Metadata

Metadata

Labels

area-xamlXAML, CSS, Triggers, Behaviorsi/regressionThis issue described a confirmed regression on a currently supported versionplatform/androidregressed-in-9.0.0s/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions