开发者

ColumnDefinition MinWidth doesn't work correctly

开发者 https://www.devze.com 2022-12-21 03:18 出处:网络
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

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 o开发者_C百科ne 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...


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消