아래 그림과 같이 '솔루션 탐색기'에서 '새 항목 추가'를 하여 "Silverlight Child Window"형식의 파일을 하나 추가한다.(파일명은 기본값으로 한다.)
















[MainPage.xaml]


<UserControl x:Class="RiaChildWindow.MainPage"

    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"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <StackPanel>

            <Button x:Name="btnOpen" Content="ChildWindow 열기" />

            <Button x:Name="btnCode" Content="코드기반으로 자식창 열기" />

        </StackPanel>

    </Grid>

</UserControl>

 

 








[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaChildWindow

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

            btnOpen.Click += new RoutedEventHandler(btnOpen_Click);

            btnCode.Click += new RoutedEventHandler(btnCode_Click);

        }

 

        void btnCode_Click(object sender, RoutedEventArgs e)

        {

            ChildWindow cw = new ChildWindow();

            Button btn = new Button();

            btn.Content = "버튼";

            btn.Width = 100; btn.Height = 100;

            cw.Content = btn; cw.Title = " 버튼 출력";

            cw.Show();

        }

 

        void btnOpen_Click(object sender, RoutedEventArgs e)

        {

            // ChildWindow 열기

            ChildWindow1 cw1 = new ChildWindow1();

            cw1.Show();

            // 무명 메서드 => 람다식

            cw1.Closed += (ss, ee) =>

            {

                bool? r = cw1.DialogResult;

                if (r != null)

                {

                    if (Convert.ToBoolean(r))

                    {

                        MessageBox.Show("확인을 클릭");

                    }

                    else

                    {

                        MessageBox.Show("취소를 클릭");

                    }

                }

            };

        }

    }

}

 

 








[ChildWindow1.xaml]


<controls:ChildWindow x:Class="RiaChildWindow.ChildWindow1"

           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"

           Width="400" Height="300"

           Title="ChildWindow1">

    <Grid x:Name="LayoutRoot" Margin="2">

        <Grid.RowDefinitions>

            <RowDefinition />

            <RowDefinition Height="Auto" />

        </Grid.RowDefinitions>

 

        <Button x:Name="CancelButton" Content="취소" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />

        <Button x:Name="OKButton" Content="확인" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />

 

    </Grid>

</controls:ChildWindow>

 
























Posted by holland14
: