none
Difference between * and Auto in wpf grid

    Question

  • What is the difference between the Grid's Rowdefinition Height="*" and Auto ?

    MSDN Forum

    Saturday, February 11, 2012 8:51 AM

Answers

  • "*" means stretch to fill the available space, and is a fraction, so if one row is * and the other row is 2* then the second row will be twice the size of the first row.

    Auto means it takes whatever/or only space it needs.

    	<Grid>
    		<Grid.RowDefinitions>
    			<RowDefinition Height="*"/>
    			<RowDefinition Height="Auto"/>
    		</Grid.RowDefinitions>
    
    		<Button Content="Test" Grid.Row="1" />
    
    	</Grid>

    So for example, you may have two rows, bottom row has a button and is Auto (only as high as the button) and the top row is "*" - stretches to the remaining space available.

    Here's a good place to start : http://msdn.microsoft.com/en-us/library/ms748828.aspx

    Regards,
    Pedro


    If you find my post helpful, please remember to "Mark As Answer" and/or "Vote as Helpful"

    Saturday, February 11, 2012 9:44 AM
    Moderator
  • Hi,

    With Auto. It means take up as much space as neccessary. 

    The star character allows you to specify columns and rows in percentages - 

    <ColumnDefinition Width="3*"/>

    <ColumnDefinition Width="7*"/>

    The 1st column is 30% and the second column is 70%. 

    With the star you can also do - 

    <ColumnDefinition Width="10*"/>
    <ColumnDefinition Width="*"/>

    This means thwe 1st column is 10 times the size of column 2. 

    Have a look at this article - 

    http://stackoverflow.com/questions/1768293/what-does-the-wpf-star-do-width-100

    Hope that helps?

    Saturday, February 11, 2012 9:47 AM
  • Auto is the default value. With * you can also use some thing like 1.5*, 2* etc which indicates the multiplicity of the widths that will be equally divided. Its is always suggested to use * or Auto rather than setting default values like 50, 100, 125 which will impact the UI based on varying resolution settings and window widths.

    Hope this helps,

    Raghu


    Raghu

    Monday, February 20, 2012 6:51 AM
  • Hi,

    without any width just behaves the same as applying Width="Auto" to the column. Auto must be the default for the column width property. 

    Sunday, February 19, 2012 10:57 AM

All replies

  • "*" means stretch to fill the available space, and is a fraction, so if one row is * and the other row is 2* then the second row will be twice the size of the first row.

    Auto means it takes whatever/or only space it needs.

    	<Grid>
    		<Grid.RowDefinitions>
    			<RowDefinition Height="*"/>
    			<RowDefinition Height="Auto"/>
    		</Grid.RowDefinitions>
    
    		<Button Content="Test" Grid.Row="1" />
    
    	</Grid>

    So for example, you may have two rows, bottom row has a button and is Auto (only as high as the button) and the top row is "*" - stretches to the remaining space available.

    Here's a good place to start : http://msdn.microsoft.com/en-us/library/ms748828.aspx

    Regards,
    Pedro


    If you find my post helpful, please remember to "Mark As Answer" and/or "Vote as Helpful"

    Saturday, February 11, 2012 9:44 AM
    Moderator
  • Hi,

    With Auto. It means take up as much space as neccessary. 

    The star character allows you to specify columns and rows in percentages - 

    <ColumnDefinition Width="3*"/>

    <ColumnDefinition Width="7*"/>

    The 1st column is 30% and the second column is 70%. 

    With the star you can also do - 

    <ColumnDefinition Width="10*"/>
    <ColumnDefinition Width="*"/>

    This means thwe 1st column is 10 times the size of column 2. 

    Have a look at this article - 

    http://stackoverflow.com/questions/1768293/what-does-the-wpf-star-do-width-100

    Hope that helps?

    Saturday, February 11, 2012 9:47 AM
  • I'd like to enhance the question a bit:

    Difference between:

    <ColumnDefinition Width="Auto" />
    
    <ColumnDefinition Width="*" />
    
    <ColumnDefinition />

    Thanks in advance,
    hfrmobile


    Programming is a kind of art but not all programmers are artists.

    Friday, February 17, 2012 12:23 PM
  • I just did that as a quick and basically the 1st column will take as much space as it needs (width of all controls in this column) and the items in the second column will take up the rest of the space available
    Friday, February 17, 2012 12:45 PM
  • <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button Content="Test" Grid.Column="0" Width="100" />
            <Button Content="Test2" Grid.Column="1" />
        </Grid>

    1st column will rtaKE UP 100 PIXELS AND THE REST OF THE SAPCE WILL BE GIVEN TO THE SECOND COLUMN.

    Even if you remvoe the 100 width from the button. The button will take up as much width as its content ("test" in this case) will require. 

    Friday, February 17, 2012 12:47 PM
  • <grid>
            <grid.columndefinitions>
                <columndefinition width="Auto">
                <columndefinition width="*">
            </columndefinition></columndefinition></grid.columndefinitions>
            <button content="Test" grid.column="0" width="100"></button>
            <button content="Test2" grid.column="1"></button>
        </grid>

    1st column will rtaKE UP 100 PIXELS AND THE REST OF THE SAPCE WILL BE GIVEN TO THE SECOND COLUMN.

    Even if you remvoe the 100 width from the button. The button will take up as much width as its content ("test" in this case) will require. 

    Thank you for your prompt reply!

    I think it is clear for every body but what about <ColumnDefinition /> so, without Width?


    Programming is a kind of art but not all programmers are artists.

    Friday, February 17, 2012 4:07 PM
  • Hi,

    without any width just behaves the same as applying Width="Auto" to the column. Auto must be the default for the column width property. 

    Sunday, February 19, 2012 10:57 AM
  • Auto is the default value. With * you can also use some thing like 1.5*, 2* etc which indicates the multiplicity of the widths that will be equally divided. Its is always suggested to use * or Auto rather than setting default values like 50, 100, 125 which will impact the UI based on varying resolution settings and window widths.

    Hope this helps,

    Raghu


    Raghu

    Monday, February 20, 2012 6:51 AM