您有两个选择。
首先,您可以使用图标资源(例如MetroCircleButtonStyle样式的示例)。
<Button Width="50"
Height="50"
Style="{DynamicResource MetroCircleButtonStyle}">
<Rectangle Width="20"
Height="20"
Fill="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Fill" Visual="{DynamicResource appbar_close}" />
</Rectangle.OpacityMask>
</Rectangle>
</Button>
其次是新的图标包
<Button Width="50"
Height="50"
Style="{DynamicResource MetroCircleButtonStyle}">
<Controls:PackIconModern Width="20" Height="20" Kind="Close" />
</Button>
正如您在Github示例中所看到的,他们在按钮内部放置了一个矩形,然后使用OpacityMask属性。
<ToggleButton Width="50"
Height="50"
IsEnabled="False"
Style="{DynamicResource MetroCircleToggleButtonStyle}">
<Rectangle Width="20"
Height="20"
Fill="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ToggleButton}}}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Fill"
Visual="{DynamicResource appbar_city}" />
</Rectangle.OpacityMask>
</Rectangle>
VisualBrush
是比较昂贵的,你可以直接使用 Drawing
。 - Dai在我的应用程序中,我之前使用了以下代码来创建带有图标的大量按钮:
<Button Command="{Binding EditDetailCommand}" ToolTip="Edit" Style="{DynamicResource buttonstyle}">
<metro:PackIconModern Width="Auto" Height="Auto" Kind="Edit" />
</Button>
<Button Width="25" Height="20">
<Button.Content>
<Rectangle Width="20" Height="20">
<Rectangle.Fill>
<VisualBrush Visual="{StaticResource appbar_close}" Stretch="None" />
</Rectangle.Fill>
</Rectangle>
</Button.Content>
</Button>
我想要将图标仅作为可点击控件,这是在最新的Mahapps版本中对我有效的方法:
<Button Width="16"
Height="16"
Padding="0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Click="HelpButton_Click"
Style="{x:Null}"
Background="Transparent"
BorderThickness="0"
>
<Button.Content>
<Icons:PackIconMaterial Kind="Help"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Button.Content>
</Button>
希望这能帮助到某个人
Content="{StaticResource appbar_close}"
我们无法知道你正在使用什么。 - ganchito55