Grid
私のHDDに突っ込んであったWPF Gridの説明。
上のXAML文は下のC#文で表現できる(多分)
XAML
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<!-- 1行1列目に配置 -->
<Button Content="Button" Grid.Row="1" Grid.Column="1" />
</Grid>
C# Code
var myGrid = new myGrid();
myGrid.ShowGridLines = "True";
var rd = new RowDefintion();
var rd2 = new RowDefintion();
var rd3 = new RowDefintion();
rd.Height = new GridLength(1.0, GridUnitType.Star);
rd2.Height = GridLength.Auto;
rd3.Height = new GridLength(2.0, GridUnitType.Star);
myGrid.RowDefinitions.Add(rd);
myGrid.RowDefinitions.Add(rd2);
myGrid.RowDefinitions.Add(rd3);
var cd = new ColumnDefinition();
var cd2 = new ColumnDefinition();
var cd3 = new ColumnDefinition();
cd.Width = new GridLength(1.0, GridUnitType.Star);
cd2.Width = GridLength.Auto;
cd3.Height = new GridLength(2.0, GridUnitType.Star);
myGrid.RowDefintions.Add(cd);
myGrid.RowDefintions.Add(cd2);
myGrid.RowDefintions.Add(cd3);
var btn = new Button();
btn.Content = "Button";
Grid.SetRow(btn, 1);
Grid.SetColumn(btn, 1);
参考
https://blog.okazuki.jp/entry/20130106/1357483477
https://docs.microsoft.com/ja-jp/dotnet/framework/wpf/controls/how-to-create-a-grid-element
https://tnakamura.hatenablog.com/entry/20100709/grid_length