我有一个带有图像的按钮
<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"
。但是,图像始终位于按钮的中间。我该如何解决?
答案 0 :(得分:1)
在Button的默认样式中,有一个 ContentPresenter 控件来显示Button的内容,它使用 HorizontalContentAlignment 属性来控制该控件的内容的水平对齐。默认值为“中心”。因此,如果要将图像放在Button的右侧,可以将HorizontalContentAlignment更改为 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>