【发布时间】:2017-01-24 09:07:14
【问题描述】:
我遇到了自动列的大小未按我想要的方式调整的问题。 我正在使用以下代码:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="10"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<TextBlock Text="User: "/>
<TextBox Grid.Row="2" Grid.Column="2" />
</Grid>
<Button Grid.Row="2" Grid.Column="1" Content="Search"/>
</Grid>
我希望它工作的方式是第二个自动列采用按钮所需的宽度(使其在网格正下方对齐),而第一个自动列采用其余部分所需的剩余宽度网格。
但是,第二列变得更长,并且宽度被划分为 * 列。看下面的截图
link to image as I do not have the right rep to post
这是我对自动列的工作方式的误解吗?如果是这样,最好的解决方法是什么。请注意,这是简化的代码,因为它是包含多于一列的表单的一部分,因此我宁愿避免将我的对象包装在其他网格或堆栈面板中。
在按钮上设置宽度也是不可能的,因为我希望它恰好是“搜索”内容所需的大小
编辑: 我想要实现的布局类似于this
【问题讨论】: