ColumnDefinition MinWidth 无法正常工作
我在 WPF (xaml) 中使用网格,并且在 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="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>
当您运行这个 xaml 代码时,您会看到前 3 列的宽度与后 5 列的宽度不同。我期望所有这些都具有相同的宽度。
有谁知道这是否是一个错误。如果有一种方法可以正确地做到这一点。
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我明白你的意思 - 黄色左边的列比右边的列宽,尽管它们应该具有相同的比例。
我想说这是一个错误,特别是当您认为以下解决方法有效时:
我猜这个错误与列按宽度分组的方式有关......
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:
I would guess that this bug is related to how the columns are grouped by width...
看起来就像它的工作方式一样。您将网格限制为 500 点,并说:嘿,让所有网格列具有相同的宽度,但该列应该至少为 250 点。现在 WPF 向您提出问题:老兄,我看到您要求我给 9 列中的每列至少 250 分,我怎样才能在 500 分内做到这一点?它做出一个决定,尊重你的最小宽度,但代价是 - 其余列的宽度。
至于正确执行此操作的方法。你是什么意思?你想要什么?
It looks like it just the way it works. You've limited grid in 500 points, and said: hey, give all grid columns the same width, but also this column should be at least 250 points. Now the question from WPF to you: Dude, I see you asked me to give each of 9 column at least 250 points, how can I do this in 500 points? And it makes a decision, to respect your minimum width, but the price is - width of the rest columns.
As for the way to do this correctly. What do you mean? What do you want?