WPF小按钮内的图标

3

我想在小的 Button 内添加图标,但它并没有按照预期的方式显示。

这是我的 XAML 代码:

<Button x:Name="eye_button"  BorderBrush="{x:Null}"   Margin="234,0,0,0"  Height="15" Width="15">                                     
        <materialDesign:PackIcon Kind="Eye"   Foreground="Black" />
  </Button>

这是它的外观:

输入图片描述

左边的正方形是按钮,右边是图标。


信息不足,请尽可能粘贴完整的XAML代码? - Dharani Kumar
尝试为图标添加高度和宽度。 - Suman Kumar
2个回答

4

试试这个:

<Button x:Name="eye_button" BorderBrush="{x:Null}"  Margin="234,0,0,0" HorizontalAlignment="Left">
    <materialDesign:PackIcon Kind="Eye" Foreground="Black" Width="15" Height="15" />
</Button>

在运行时,它应该看起来像这样:

enter image description here


2
 <Button
    Width="15"
    Height="15"
    Padding="0"
    HorizontalAlignment="Center"
    HorizontalContentAlignment="Center"
    VerticalContentAlignment="Center"
    Background="Transparent"
    BorderThickness="0"
    Foreground="Red">

    <materialDesign:PackIcon
        Width="15"
        Height="15"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        Foreground="Black"
        Kind="ArrowBack" />
</Button>

请确保将padding设置为0。

enter image description here


图标的填充通常是关键。 - ojonasplima

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接