填充出现在 UniformGrid 的底部

Dra*_*cir 1 c# wpf xaml

我有下面的 XAML,它显示了 UniformGrid 中按钮下的一些填充:

<Grid>
  <UniformGrid Background="#CCC"
               HorizontalAlignment="Stretch"
               VerticalAlignment="Bottom"
               Margin="8,8,8,0">
    <Button Height="28"
            Margin="5">
      OK
    </Button>
    <Button Height="28"
            Margin="5">
      Cancel
    </Button>
  </UniformGrid>
</Grid>
Run Code Online (Sandbox Code Playgroud)

它显示为:

2 个按钮

但是,如果我删除其中一个按钮,则不会发生填充:

1 个按钮

当 XAML 中有 2 个按钮时,如何删除此填充?

我已经尝试了明显的PaddingMargin属性,但它仍然是一样的。

dza*_*ala 5

尝试指定行数:

<UniformGrid Rows="1" />
Run Code Online (Sandbox Code Playgroud)

UniformGrid 会根据添加的元素数量自动设置列数和行数。看看这个帖子