ColumnDefinition MinWidth无法正常工作 [英] ColumnDefinition MinWidth doesn't work correctly
问题描述
我在WPF(xaml)中使用Grid,在ColumnDefinition中使用MinWidth属性时我有一些奇怪的效果。例如,当我使用9 ColumnDefinition并且每个ColumnDefinition具有'Width =*'属性并且其中一个中间列也具有MinWidth属性时,则其他列的大小是错误的。
好吧,很难描述,但是这个xaml代码很好地说明了它:
< Grid Width = 500 >
< Grid.ColumnDefinitions>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*MinWidth =250/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< /Grid.ColumnDefinitions>
< Border Grid.Column =0Background =Green/>
< Border Grid.Column =1Background =Blue/>
< Border Grid.Column =2Background =Red/>
< Border Grid.Column =3Background =Yellow/>
< Border Grid.Column =4Background =Purple/>
< Border Grid.Column =5Background =Orange/>
< Border Grid.Column =6Background =Azure/>
< Border Grid.Column =7Background =LightBlue/>
< Border Grid.Column =9Background =LightGreen/>
< / Grid>
运行这个xaml代码时,您会看到前3列的宽度与最后5列。我希望所有这些都具有相同的宽度。
有谁知道这是否是一个错误。如果有办法做到这一点。
预先致谢。
div>我明白你的意思 - 黄色左边的列比右边的列宽,即使它们的比例相同。
我会说这是一个错误,尤其是当您认为以下解决方法有效时:
< Grid.ColumnDefinitions>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =1.0000001 *MinWidth =250/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< ColumnDefinition Width =*/>
< /Grid.ColumnDefinitions>
我猜这个错误与列按宽度分组的方式有关...... p>
I'm using a Grid in WPF (xaml) and I'm have some strange effect when using the MinWidth property in a ColumnDefinition. For example, when I use 9 ColumnDefinition and every ColumnDefinition has the 'Width="*"' property and one of the middle columns also has a MinWidth property then the size of the other columns is wrong.
Well, it's hard to discribe but this xaml code illustrates it nicely:
<Grid Width="500">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*" MinWidth="250"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="Green"/>
<Border Grid.Column="1" Background="Blue"/>
<Border Grid.Column="2" Background="Red"/>
<Border Grid.Column="3" Background="Yellow"/>
<Border Grid.Column="4" Background="Purple"/>
<Border Grid.Column="5" Background="Orange"/>
<Border Grid.Column="6" Background="Azure"/>
<Border Grid.Column="7" Background="LightBlue"/>
<Border Grid.Column="9" Background="LightGreen"/>
</Grid>
When you run this xaml code you'll see that the first 3 columns have a different width than the last 5 columns. Where I expected all of those to have the same width.
Does anyone know if this is a bug. And if there is a way to do this correctly.
Thanks in advance.
I see what you mean - the columns to the left of the yellow one are wider than the columns to the right, even though they are meant to be given the same proportions.
I would say it's a bug, especially when you consider that the following workaround works:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1.0000001*" MinWidth="250"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
I would guess that this bug is related to how the columns are grouped by width...
这篇关于ColumnDefinition MinWidth无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!