Popup 컨트롤 - 컨트롤과 코드 기반으로 팝업 출력
.NET프로그래밍/Silverlight 3.0 2009. 12. 15. 10:02 |Popup 컨트롤 - 팝업창을 띄울 수 있는 영역 제공
아래 그림과 같이 '솔루션 탐색기'에서 "이미지파일"인 "img0"파일을 붙여넣는다.
[MainPage.xaml]
<UserControl x:Class="RiaPopup.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="btnAdd" Content="방명록 글쓰기(팝업창 열기)" />
<Button x:Name="btnCode" Content="코드기반으로 팝업창 열기" />
</StackPanel>
<Popup x:Name="myPopup" IsOpen="False" HorizontalOffset="20" VerticalOffset="20">
<Border BorderBrush="Red" BorderThickness="2" Width="320" Height="240">
<StackPanel>
<TextBlock Text="이름 : " />
<TextBlock Text="내용 : " />
<Button x:Name="btnClose" Content="팝업창 닫기" />
</StackPanel>
</Border>
</Popup>
</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;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Imaging;
namespace RiaPopup
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
btnAdd.Click += new RoutedEventHandler(btnAdd_Click);
btnClose.Click += new RoutedEventHandler(btnClose_Click);
btnCode.Click += new RoutedEventHandler(btnCode_Click);
}
void btnCode_Click(object sender, RoutedEventArgs e)
{
Popup p = new Popup();
Image i = new Image();
i.Source = new BitmapImage(new Uri("img0.jpg", UriKind.Relative));
i.Width = 320;
i.Height = 240;
//i.MouseLeftButtonDown += new MouseButtonEventHandler(i_MouseLeftButtonDown);
i.MouseLeftButtonDown += delegate(object ss, MouseButtonEventArgs ee) { p.IsOpen = false; };
p.Child = i; // 이미지 등록
p.IsOpen = true; // 오픈
}
//void i_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
//{
// p.IsOpen = false;
//}
void btnClose_Click(object sender, RoutedEventArgs e)
{
this.myPopup.IsOpen = false; // 닫기
}
void btnAdd_Click(object sender, RoutedEventArgs e)
{
this.myPopup.IsOpen = true; // 열기
}
}
}
'.NET프로그래밍 > Silverlight 3.0' 카테고리의 다른 글
격리 저장소(Isolated Storage) - 실습 : 마지막 방문시간 출력하기 (0) | 2009.12.15 |
---|---|
ChildWindow로 모달 팝업 구현 (0) | 2009.12.15 |
Microsoft의 무료 실버라이트 배포 공간 (0) | 2009.12.15 |
배포 - IIS 웹 서버에 MIME 타입 추가하기 (0) | 2009.12.15 |
실습 : 미니프로젝트 : 한줄 메모장 (SQL + WCF + Silverlight) (0) | 2009.12.14 |