[Silverlight] RowDefinition・ColumnDefinitionの「Auto」「*」をコード側から指定する方法

10:33 PM on 2011年5月26日 ,

Grid g = new Grid();

// RowDefinition
RowDefinition row1 = new RowDefinition();
row1.Height = new GridLength(1.0, GridUnitType.Auto); // <RowDefinition Height="Auto"/>
g.RowDefinitions.Add(row1);

RowDefinition row2 = new RowDefinition();
row2.Height = new GridLength(1.0, GridUnitType.Star); // <RowDefinition Height="*"/>
g.RowDefinitions.Add(row2);

RowDefinition row3 = new RowDefinition();
row3.Height = new GridLength(0.5, GridUnitType.Star); // <RowDefinition Height="0.5*"/>
g.RowDefinitions.Add(row3);

RowDefinition row4 = new RowDefinition();
row4.Height = new GridLength(2.0, GridUnitType.Star); // <RowDefinition Height="2.0*"/>
g.RowDefinitions.Add(row4);

// ColumnDefinition
ColumnDefinition col1 = new ColumnDefinition();
col1.Width = new GridLength(1.0, GridUnitType.Auto); // <ColumnDefinition Height="Auto"/>
g.ColumnDefinitions.Add(col1);

ColumnDefinition col2 = new ColumnDefinition();
col2.Width = new GridLength(1.0, GridUnitType.Star); // <ColumnDefinition Height="*"/>
g.ColumnDefinitions.Add(col2);