Search code examples
xamluno-platform

Style reference works on UWP but not on Android or Wasm


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


Solution

  • 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>