tags:

views:

701

answers:

3

What does exactly the star in size terms in WPF mean?

+8  A: 

If you have 2 columns like this:

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

it means that the first column is 10x wider than the second. It's like saying "10 parts column 1, and 1 part column 2."

The cool thing about this is that your columns will resize proportionally. Other options are:

//Take up as much space as the contents of the column need
<ColumnDefinition Width="Auto"/>
//Fixed width: 100 pixels
<ColumnDefinition Width="100"/>

Hope that helps!

Pwninstein
+1  A: 

In addition, you can leave out the "*" if that's the element of unit size. So using Pwninstein's code example, it would just be:

<ColumnDefinition Width="10*/>
<ColumnDefinition/>
Dave
+1  A: 

Another example, to give 30% to column 1 and 70% to column 2 -

<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="7*"/>

And likewise for rows -

<RowDefinition Height="3*"/>
<RowDefinition Height="7*"/>

I am sure everyone else knows this, but I didn't until recently: the numbers do not have to be integers (following Dave's example) -

<ColumnDefinition Width="1.5*/>
<ColumnDefinition/>
Edward