You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WPF UniformGrid控件问题:添加第三个按钮自动换行求助

解决WPF UniformGrid添加第三个按钮换行的问题

UniformGrid默认未指定行列数时,会自动计算布局,尽量让行列数接近。3个元素的情况下,它会生成2列2行的网格,第三个按钮自然就被挤到下一行了。

要让三个按钮排在同一行,直接给UniformGrid加上Columns="3"属性就行,强制指定列数为3,所有元素会依次填满每一列,不会换行:

<UniformGrid Grid.Row="2" HorizontalAlignment="Right" Columns="3">
    <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>

如果之后要添加更多按钮,只要同步调整Columns的值为对应数量,就能保持所有按钮在同一行。

内容的提问来源于stack exchange,提问作者Philip Borchert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 20:30:32