我已经将Style定义为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。这些是唯一经过测试的平台
必须使用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>
您已经定义了名为"按钮样式";而是引用了名为";底部条形按钮";(我猜这在其他地方有定义(。
试过这个吗?
<Button Grid.Column="0" Style="{StaticResource ButtonStyle}">
...
</Button>
<Button Grid.Column="1" Style="{StaticResource ButtonStyle}">
...
</Button>