WPF中TableColumn和GridColumn的Auto和Star之间的差异

时间:2022-11-13 10:29:41

In Grid, Auto means the content width will define the column width, and Star means the column width will use the left space available.

在Grid中,Auto表示内容宽度将定义列宽,Star表示列宽将使用可用的左侧空间。

However in Table, I find a different behavior. If you have 3 columns with the width: 100, Auto, 100; the width second column does not depend on its content. Instead, it uses the remaining space available as its width.

但是在表中,我发现了不同的行为。如果你有3列宽度:100,自动,100;宽度第二列不依赖于其内容。相反,它使用剩余的可用空间作为其宽度。

Moreover in Table, if you combine Star column with Auto or fixed pixel width column, the Star column will be very small, around 1 character width.

此外,在表格中,如果将“星形”列与“自动”或“固定像素宽度”列组合,则“星形”列将非常小,大约1个字符宽度。

Could anyone explain whether this is a bug in Table, or it's simply the default behavior?

任何人都可以解释这是否是表中的错误,或者它只是默认行为?


Additional info: If I combine Auto with fixed width, the Auto column (the second) will use the remaining space available.

附加信息:如果我将Auto与固定宽度组合,则Auto列(第二个)将使用剩余可用空间。

<Table>
  <Table.Columns>
    <TableColumn Width="100"/>
    <TableColumn Width="Auto"/>
    <TableColumn Width="100"/>
  </Table.Columns>
  <TableRowGroup>
    <TableRow>
      <TableCell>...
      <TableCell>...
      <TableCell>...
    </TableRow>
  </TableRowGroup>
</Table>

WPF中TableColumn和GridColumn的Auto和Star之间的差异

If I combine Star with fixed width or Auto, the Star column's width is very small, and the other columns will be divided equally on the remaining space available.

如果我将Star与固定宽度或自动组合,则Star列的宽度非常小,其他列将在剩余可用空间上平均分配。

<Table>
  <Table.Columns>
    <TableColumn Width="*"/>
    <TableColumn Width="100"/>
    <TableColumn Width="100"/>
  </Table.Columns>
  <TableRowGroup>
    <TableRow>
      <TableCell>...
      <TableCell>...
      <TableCell>...
    </TableRow>
  </TableRowGroup>
</Table>

WPF中TableColumn和GridColumn的Auto和Star之间的差异

1 个解决方案

#1


2  

Okay I understand that this is not an answer as such, but since there's no one else responding at the moment, I figured I'd try to help out a little bit. This appears to be a bug that's been around since at least WPF 4.0

好吧,我明白这不是一个答案,但由于此刻没有其他人回应,我想我会尝试帮助一点点。这似乎是至少从WPF 4.0开始出现的错误

https://connect.microsoft.com/VisualStudio/feedback/details/724483/the-width-of-tablecolumns-in-a-wpf-flowdocument-doesnt-work-with-non-star-widths

Tables appear to be relatively useless unless you're using the star notation, which, as near as I can tell basically functions more like a percentage, but there's some flaky behavior in there as well.

表格似乎相对无用,除非你使用星号表示法,尽管我基本上可以说基本功能更像百分比,但是那里也存在一些不稳定的行为。

If you set everything to star it basically does the equivalent of auto across the board, but setting one or more elements to anything but star will cause the existing stars to occupy 1 percent the total width, likewise if you changed it to 50* it would take up 50 percent of the total width.

如果你把所有东西都设置成星星,那么它基本上相当于全面自动,但是将一个或多个元素设置为除了星星以外的任何元素将导致现有星星占据总宽度的1%,同样如果你将其改为50 *它会占总宽度的50%。

I know this isn't extremely helpful, but it's the best I could do.

我知道这不是很有帮助,但这是我能做的最好的。

#1


2  

Okay I understand that this is not an answer as such, but since there's no one else responding at the moment, I figured I'd try to help out a little bit. This appears to be a bug that's been around since at least WPF 4.0

好吧,我明白这不是一个答案,但由于此刻没有其他人回应,我想我会尝试帮助一点点。这似乎是至少从WPF 4.0开始出现的错误

https://connect.microsoft.com/VisualStudio/feedback/details/724483/the-width-of-tablecolumns-in-a-wpf-flowdocument-doesnt-work-with-non-star-widths

Tables appear to be relatively useless unless you're using the star notation, which, as near as I can tell basically functions more like a percentage, but there's some flaky behavior in there as well.

表格似乎相对无用,除非你使用星号表示法,尽管我基本上可以说基本功能更像百分比,但是那里也存在一些不稳定的行为。

If you set everything to star it basically does the equivalent of auto across the board, but setting one or more elements to anything but star will cause the existing stars to occupy 1 percent the total width, likewise if you changed it to 50* it would take up 50 percent of the total width.

如果你把所有东西都设置成星星,那么它基本上相当于全面自动,但是将一个或多个元素设置为除了星星以外的任何元素将导致现有星星占据总宽度的1%,同样如果你将其改为50 *它会占总宽度的50%。

I know this isn't extremely helpful, but it's the best I could do.

我知道这不是很有帮助,但这是我能做的最好的。