반응형

StackPanel은 자신의 자식 요소를 행이나 열에 나열하는 매우 간단한 패널, 아마도 모든 사용자 인터페이스의 레이아웃을 위해 사용하지 않을 것이다. 자식 요소들을 수직 또는 수평으로 순서대로 나열한다. 매우 간단하며, 레이아웃의 관점에서 볼 때 작은 부분을 관리하기에 유용하다.

Ex 1

<Window x:Class="WpfApplication15.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel Background="AliceBlue">//StackPanel Background, 배경의 색을 지정해준다.
            <TextBox Margin="3">검색어</TextBox>//Margin은 간격이라고 생각을 하면 된다.
            <ComboBox Margin="3"/>
            <TextBox Margin="3">검색어</TextBox>
            <ComboBox Margin="3"/>
            <Button Margin="3.5"/>
            <CheckBox Margin="3">검색 시작</CheckBox>
            <CheckBox Margin="3">제목만 검색</CheckBox>
            <CheckBox Margin="3">연관 단어 검색</CheckBox>
            <CheckBox Margin="3">검색어 표시</CheckBox>
        </StackPanel>
    </Grid>
</Window>

 

위에 소스를 보면 TextBox, ComboBox, CheckBox, Button을 생성하는 것을 볼 수 있다.

 

 

From Programming WPF

 

Ex 2

<Window x:Class="WpfApplication15.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel Background="AliceBlue">
            <Label Name="label1">Hello</Label>
            <Button Name="btn1" Height="100" Width="100" Click="btn1_Click" Content="Hello"></Button>
        </StackPanel>
    </Grid>
</Window>
<!------------------------------------------------------------------------------------------------------------------------>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication15
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();


        }

        private void btn1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("끔");
        }
    }
}

StackPanel에 간단히 글을 작성하고 버튼을 눌러 이벤트를 생성 해봄

반응형

'프로그래밍 > WPF' 카테고리의 다른 글

[WPF] Binding Property  (0) 2013.08.02
[WPF] Binding(바인딩)  (0) 2013.08.01
[WPF] Dynamic Resource & Static Resource  (0) 2013.05.21
[WPF] WrapPanel & DockPanel  (0) 2013.05.15
[WPF] XAML 주석처리  (0) 2013.05.14