Style reference works on UWP but not on Android or Wasm

Viewed 73

I have defined a Style as a UserControl's resource.

...
<UserControl.Resources>
  <Style x:Key="BottomBarButton" TargetType="Button">
    <Setter Target="Background" Value="Transparent"/>
      <Setter Target="BorderThickness" Value="1"/>
      <Setter Target="HorizontalAlignment" Value="Stretch"/>
      <Setter Target="VerticalAlignment" Value="Stretch"/>
    </Style>
</UserControl.Resources>
...

and it's used

...
<Button Grid.Column="0" Style="{StaticResource BottomBarButton}">
  ...
</Button>
<Button Grid.Column="1" Style="{StaticResource BottomBarButton}">
  ...
</Button>
...

This work on UWP, but the style does not apply on Android or Wasm. These are the only tested platforms

2 Answers

Must use Property instead of Target.

<Style x:Key="BottomBarButton" TargetType="Button">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="HorizontalAlignment" Value="Stretch"/>
    <Setter Property="VerticalAlignment" Value="Stretch"/>
</Style>

You've defined the style named "ButtonStyle" but are referencing a style named "BottomBarButton" (which I'm guessing is defined elsewhere).

Tried this?

<Button Grid.Column="0" Style="{StaticResource ButtonStyle}">
  ...
</Button>
<Button Grid.Column="1" Style="{StaticResource ButtonStyle}">
  ...
</Button>
Related