What does * mean in XAML
What does * mean in XAML. I have a grid of width 400. And divided the grid to 3 columns. What does *.4 mean? I thought it is 40% of the space available. so thought the first 2 colu开发者_Go百科mns will get 40% percent each and the rest is taken by the third column. but looks like, the third column is taking 60% and the first two are getting 20% each. How does this work?
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".4*"/>
<ColumnDefinition Width=".4*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
Basically, the default is "1*", so what you have above is effectively:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.4*" />
<ColumnDefinition Width="0.4*" />
<ColumnDefinition Width="1.0*" />
</Grid.ColumnDefinitions>
The Star grid spacing (GridUnitType.Star) proportionally distributes space. In your case, you have a total of 1.8 (1.0 + 0.4 + 0.4), so the first two columns each get 22.2% (0.4/1.8) of the width allocated to them.
To get what you want, you can use:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.4*" />
<ColumnDefinition Width="0.4*" />
<ColumnDefinition Width="0.2*" />
</Grid.ColumnDefinitions>
This sets the total to 1.0, so each becomes a percentage.
Note that this will give exactly the same result as doing:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40*" />
<ColumnDefinition Width="40*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
Since the total proportions are divided up by the total (100) now, still giving 40%, 40%, 20%.
精彩评论