样式参考适用于 UWP 但不适用于 Android 或 Wasm

Style reference works on UWP but not on Android or Wasm

我已将样式定义为 UserControl 的资源。

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

并且已经使用

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

这适用于 UWP,但样式不适用于 Android 或 Wasm。这些是唯一经过测试的平台

您已经定义了名为“ButtonStyle”的样式,但正在引用名为“BottomBarButton”的样式(我猜它是在别处定义的)。

试过这个吗?

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

必须使用 Property 而不是 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>