Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Auto and Star for TableColumn and GridColumn in WPF

Tags:

layout

wpf

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

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.

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.

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.

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

screenshot 1

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.

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

screenshot 2

like image 587
erika Avatar asked Aug 23 '11 04:08

erika


People also ask

What is the difference between * and Auto in WPF?

Auto − It will take space which are required for the controls in that specific row/column. Star (*) − It will take the remaining space when Auto and fixed sized are filled.

What is Star in WPF?

In a WPF Grid, Width="*" or Height="*" means proportional sizing.

What is WPF Auto?

Auto means that a column is given as much width as the elements within it require. The width of * sized columns is calculated by allocating space for the Auto , and fixed width columns, and then dividing up the remaining space.


1 Answers

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

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.

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

like image 166
dmalicoat Avatar answered Oct 20 '22 01:10

dmalicoat