Grid column authorization to fit the remaining space in the parent

In WPF, I have time trying to set up the grid correctly.

I have the following layout for my grid:

<ItemsControl HorizontalContentAlignment="Stretch"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/> <ColumnDefinition Width="100"/> </Grid.ColumnDefinitions> <Label Grid.Column="0" /> <Label Grid.Column="1"/> <TextBox Grid.Column="2"/> <Button Grid.Column="3"/> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 

The problem is that Width = "Auto" apparently determines the size of the column in the width of the content and does not fill the extra space in the parent container. This leaves the rest of the columns with jagged and ugly spaces at the end of each row.

I probably missed something simple, but I cannot find a method suitable for the corresponding column.

Or is there better control over work?

+5
wpf grid
Sep 14 '12 at 21:24
source share
2 answers

* means fill or split. If you had two s * , they would split the width evenly.

 <ColumnDefinition Width="*"/> 
+9
Sep 14 '12 at 21:40
source share

I think I found a solution after a bit of work.

The problem was this: <ColumnDefinition Width="Auto"/>

This caused the column to match the content. I changed it to: <ColumnDefinition />

This causes the column to fit in the empty space remaining in the parent container, regardless of the size of the content.

0
Sep 14 '12 at 21:29
source share



All Articles