Assign percentage width to a column in silverlight grid
I was wondering how can I define the column widths for a silverlight/WPF grid with percentages like we use to define in html tables. This msdn document was quite helpful. Let me paste the important part here. The width attribute can take three type of values:
- doubleValue: The column's width, expressed as a floating-point value for a pixel count. Typically this is given as an integer, although interpolation of floating-point values is supported by grid layout.
- starSizing: A convention by which you can size rows or columns to take remaining available space in the Grid. A starSizing always includes the literal character *, and optionally precedes the * with an integer value that specifies what share of available space should be given as a weighted factor versus other possible star sizings (for example, 3*).
- Auto: The column's width, described by the literal Auto.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height=".5*"></RowDefinition>
<RowDefinition Height=".5*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
<ColumnDefinition Width="3*"></ColumnDefinition>
</Grid.ColumnDefinitions>
</Grid>
The .5* in the row height can be changed to any value but both values must be same to make sure the rows are divided evenly.
Labels: grid, height, layout, percentage, silverlight, size, width