.NET/WPF

Grid 패널에 배치하기 [언제나 WPF]

언제나휴일 2020. 5. 28. 12:08
반응형

 

이번 강의는 Window.xaml에 디폴트로 제공하는 Grid 패널에 컨트롤을 배치해 볼 거예요.

배치할 모습
Grid의 행과 열 폭 결정하기
원하는 행과 열에 배치하기
여러 행이나 여러 열 차지하기

<Window x:Class="Grid_실습_Xaml을_이용.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Grid_실습_Xaml을_이용"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="2*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="60"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="80"/>
        </Grid.ColumnDefinitions>
        <TextBlock x:Name="tb_name" Text="이름"
                   VerticalAlignment="Center"/>
        <TextBlock x:Name="tb_age" Text="나이"
                   Grid.Row="1"
                   VerticalAlignment="Center"/>
        <TextBlock x:Name="tb_intro" Text="소개"
                   Grid.Row="2"
                   VerticalAlignment="Center"/>
        <TextBox x:Name="tbox_name"
                 Grid.Column="1"
                 Grid.ColumnSpan="2"
                 Margin="2,2,2,2" Background="Cyan"/>
        <TextBox x:Name="tbox_age"
                 Grid.Row="1"
                 Grid.Column="1"
                 Grid.ColumnSpan="2"
                 Margin="2,2,2,2" Background="Cyan"/>
        <TextBox x:Name="tbox_intro"
                 Grid.Row="2"
                 Grid.Column="1"                 
                 Margin="2"
                 AcceptsReturn="True"
                 Background="Cyan"/>
        <Button x:Name="btn_ok" Grid.Row="2"
                Grid.Column="2" Content="등록"/>
        <TextBlock x:Name="tb_about"
                   Text="Grid를 이용하여 배치하기"
                   Grid.Row="3"
                   Grid.ColumnSpan="3"
                   HorizontalAlignment="Center"/>
    </Grid>
</Window>
반응형