XAML
<Grid x:Name="MyGrid" Width="400" Height="400" ShowGridLines="True">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
</Grid>

 

CS
Grid grid = new Grid();
grid.RowDefinitions.Add(new RowDefinition());
grid.RowDefinitions.Add(new RowDefinition());

grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition());

grid.ShowGridLines = true;


by 피요히코~ 2009. 11. 24. 23:19

<XAML> 

 

 <Grid ShowGridLines="True"> <!--ShowGridLines : 그리드 라인 보이기 옵션-->

<Grid.ColumnDefinitions> <!--3열 정의-->

<ColumnDefinition Width="50"></ColumnDefinition>

<ColumnDefinition Width="*"></ColumnDefinition>

<ColumnDefinition Width="50"></ColumnDefinition>

</Grid.ColumnDefinitions>

<Grid.RowDefinitions><!--2행 정의-->

<RowDefinition Height="50"></RowDefinition>

<RowDefinition></RowDefinition>

</Grid.RowDefinitions>

<!--<Button Grid.Column="0">Btn1</Button>--><!--들어갈 열값 명시 - 디폴드는 다 0행0열-->

<StackPanel Grid.Column="0">

<Button>Btn1</Button>

<Button>Btn4</Button>

</StackPanel>

<Button Grid.Column="1">Btn2</Button>

<Button Grid.Column="2">Btn3</Button>

<!--Grid는 들어갈 행과 열을 하나하나 지정해줘야함-->

<Button Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2">Btn5</Button> </Grid>

 


 

 

<C#>

//Grid

Grid grid = new Grid();

this.Content = grid;

grid.ShowGridLines = true; //gridline

RowDefinition row = new RowDefinition();//행

row.Height = new GridLength(100);//높이지정  //전체크기가 300x300

grid.RowDefinitions.Add(row);

row = new RowDefinition();

row.Height = GridLength.Auto;

grid.RowDefinitions.Add(row);

ColumnDefinition col = new ColumnDefinition();//열

col.Width = new GridLength(100);//너비지정

grid.ColumnDefinitions.Add(col);

col = new ColumnDefinition();

grid.ColumnDefinitions.Add(col);

//Label

Label label = new Label();

label.Content = "문자열 : ";

grid.Children.Add(label); //일단 label을 grid에 넣어준다. 그 후에 장소지정

Grid.SetRow(label, 0);//0행 <Label Grid.Row="0">

Grid.SetColumn(label, 1);//0열 <Label Grid.Colum="1">

//TestBox

TextBox txt = new TextBox();

txt.BorderBrush = Brushes.Red;

txt.BorderThickness = new Thickness(1);

grid.Children.Add(txt);

Grid.SetRow(txt, 1);

Grid.SetColumn(txt, 1);

//Button

Button btn = new Button();

btn.Content = "버튼";

grid.Children.Add(btn);

Grid.SetRow(btn, 0);

Grid.SetColumn(btn, 0);//일단 위치 지정후 병합

Grid.SetRowSpan(btn, 2); //병합할대상, 병합할 셀의 수  //<Button Grid.RowSpan="2">


by 피요히코~ 2009. 2. 25. 12:50
| 1 |