Horizo​​ntalAlignment对于按钮(UWP)中的图像不起作用

时间:2020-05-14 18:36:01

标签: xaml uwp uwp-xaml

我有一个带有图像的按钮

        <Button BorderThickness="0" Background="Black"  Grid.Column="0" Width="400" >
        <Image HorizontalAlignment="Right" Height="20" Source="ms-appx:///Assets/LockScreenLogo.scale-200.png" Width="20"  />
    </Button>

我希望图像位于按钮的右端,所以给了HorizontalAlignment="Right"。但是,图像始终位于按钮的中间。我该如何解决?

enter image description here

1 个答案:

答案 0 :(得分:1)

在Button的默认样式中,有一个 ContentPresenter 控件来显示Button的内容,它使用 Horizo​​ntalContentAlignment 属性来控制该控件的内容的水平对齐。默认值为“中心”。因此,如果要将图像放在Button的右侧,可以将Horizo​​ntalContentAlignment更改为 Right

<Button HorizontalContentAlignment="Right" BorderThickness="0" Background="Black"  Grid.Column="0" Width="400" >
    <Image Height="20" Source="ms-appx:///Assets/LockScreenLogo.scale-200.png" Width="20"  />
</Button>