ChildWindow로 모달 팝업 구현
.NET프로그래밍/Silverlight 3.0 2009. 12. 15. 10:44 |아래 그림과 같이 '솔루션 탐색기'에서 '새 항목 추가'를 하여 "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>
'.NET프로그래밍 > Silverlight 3.0' 카테고리의 다른 글
Open File Dialog 컨트롤 (0) | 2009.12.15 |
---|---|
격리 저장소(Isolated Storage) - 실습 : 마지막 방문시간 출력하기 (0) | 2009.12.15 |
Popup 컨트롤 - 컨트롤과 코드 기반으로 팝업 출력 (0) | 2009.12.15 |
Microsoft의 무료 실버라이트 배포 공간 (0) | 2009.12.15 |
배포 - IIS 웹 서버에 MIME 타입 추가하기 (0) | 2009.12.15 |