WPF xaml UniformGrid将第三个控件放在单独的行上

pn9klfpd  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(174)

当我放置第三个按钮时,它会转到下一行,我需要使用UniformGrid的帮助。

<UniformGrid Grid.Row="2" HorizontalAlignment="Right">
    <Button  x:Name="RuntimeButton" Style="{StaticResource BigButton}" Command="{Binding SelectRuntimeCommand}">Runtime</Button>
    <Button  x:Name="ConfigButton" Style="{StaticResource BigButton}" Command="{Binding SelectConfigureCommand}">Configure</Button>
    <Button  x:Name="LogButton" Style="{StaticResource BigButton}">Log</Button>
</UniformGrid>
c86crjj0

c86crjj01#

设置Rows="1"以明确表示您需要单行,并且列数将等于子元素的计数(这样可以防止将来的更改,例如添加/删除/隐藏按钮)

<UniformGrid Grid.Row="2" Rows="1" HorizontalAlignment="Right">
    <Button  x:Name="RuntimeButton" Style="{StaticResource BigButton}" Command="{Binding SelectRuntimeCommand}">Runtime</Button>
    <Button  x:Name="ConfigButton" Style="{StaticResource BigButton}" Command="{Binding SelectConfigureCommand}">Configure</Button>
    <Button  x:Name="LogButton" Style="{StaticResource BigButton}">Log</Button>
</UniformGrid>
kpbpu008

kpbpu0082#

UniformGrid似乎在内部设置了Columns=2,因此如果您希望右侧有三个项目,则必须设置Columns=3

<UniformGrid Grid.Row="2" Columns="3" HorizontalAlignment="Right">

相关问题