如何将图标放入按钮(MahApps)

Chr*_*emm 4 wpf mahapps.metro

我想将MahApps库中的图标放入普通按钮.我这样试过:

<Button Height="20" Width="25" Background="Transparent" Foreground="White" Content="{StaticResource appbar_close}"/>
Run Code Online (Sandbox Code Playgroud)

结尾如下:

那么如何在适当的位置将此图标集成到此按钮中?

pun*_*r76 16

你有2个选择.

首先,您可以使用Icon rersources(使用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>
Run Code Online (Sandbox Code Playgroud)

第二个是新的Icon包

<Button Width="50"
        Height="50"
        Style="{DynamicResource MetroCircleButtonStyle}">
    <Controls:PackIconModern Width="20" Height="20" Kind="Close" />
</Button>
Run Code Online (Sandbox Code Playgroud)

希望有所帮助.