如何在按钮之间有空格的堆栈面板中添加多个按钮

How to add several button in stack panel with spaces between buttons

我尝试在 StackPanel 中放置几个​​按钮:

<StackPanel Orientation="Horizontal">
    <Button Content="" HorizontalAlignment="Left" Margin="10,590,1,-40"
        VerticalAlignment="Top" RenderTransformOrigin="1.25,0.964">
    </Button>
    <Button Content="Add" HorizontalAlignment="Left" Margin="10,590,10,-40" 
        VerticalAlignment="Top" RenderTransformOrigin="1.25,0.964">
    </Button>
</StackPanel>

我的所有 Buttons 对齐都在右侧,这没问题,但它们之间没有空格。

有什么建议吗?

使用边距属性.....

默认值为左、上、右、下,因此在您的示例代码中,左 = 10、上 = 590、右 = 1 和下 = -40。

将 Left/Right 页边距更改为合理的值。这是一些(清理过的)示例代码:

<StackPanel Orientation="Horizontal">
    <Button Content="" Margin="0,0,10,0" VerticalAlignment="Top" />
    <Button Content="Add" Margin="0,0,10,0" VerticalAlignment="Top" />
</StackPanel>