Skip to content

Add page level style makes the label invisible on Windows #33280

@suugbut

Description

@suugbut

Description

The following just works fine on both Windows and Android.

<CollectionView>
    <CollectionView.ItemsSource>
        <x:Array Type="{x:Type x:String}">
            <x:String>Item 1</x:String>
            <x:String>Item 2</x:String>
        </x:Array>
    </CollectionView.ItemsSource>
    <CollectionView.ItemTemplate>
        <DataTemplate x:DataType="{x:Type x:String}">
            <Grid Padding="10">
                <OnPlatform x:TypeArguments="View">
                    <On Platform="Android">
                        <Label Text="{Binding}" />
                    </On>
                    <On Platform="WinUI">
                        <Label Text="{Binding}" />
                    </On>
                </OnPlatform>
            </Grid>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

But adding page level style below,

<ContentPage.Resources>
    <Style TargetType="Label">
        <Setter Property="FontSize"
                Value="30" />
    </Style>
</ContentPage.Resources>

makes the Label invisible on Windows.

Steps to Reproduce

Replace ContentPage of the MainPage with my code above.

Link to public reproduction project repository

Not needed

Version with bug

10.0.20

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows 10

Did you find any workaround?

Explicitly specify BackgroundColor of the Label on Windows section:

  <On Platform="WinUI">
       <Label Text="{Binding}" BackgroundColor="White" />
  </On>

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions