0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WPF GridのC# Code

Last updated at Posted at 2019-06-17

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

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?