728x90
반응형
728x170
▶ MainPage.xaml
<Page x:Class="TestProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestProject"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Name="contentGrid"
Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="메시지 대화 상자 표시하기"
Click="button_Click" />
</Grid>
</Page>
728x90
▶ MainPage.xaml.cs
using System;
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace TestProject
{
/// <summary>
/// 메인 페이지
/// </summary>
public sealed partial class MainPage : Page
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 비동기 작업
/// </summary>
private IAsyncOperation<IUICommand> asyncOperation;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainPage()
/// <summary>
/// 생성자
/// </summary>
public MainPage()
{
this.InitializeComponent();
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 버튼 클릭시 처리하기 - button_Click(sender, e)
/// <summary>
/// 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private async void button_Click(object sender, RoutedEventArgs e)
{
MessageDialog messageDialog = new MessageDialog("색상을 선택해 주시기 바랍니다.", "색상 선택");
messageDialog.Commands.Add(new UICommand("빨강", null, Colors.Red ));
messageDialog.Commands.Add(new UICommand("녹색", null, Colors.Green));
messageDialog.Commands.Add(new UICommand("파랑", null, Colors.Blue ));
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Interval = TimeSpan.FromSeconds(5);
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Start();
this.asyncOperation = messageDialog.ShowAsync();
IUICommand uiCommand = null;
try
{
uiCommand = await asyncOperation;
}
catch(Exception)
{
}
dispatcherTimer.Stop();
if(uiCommand == null)
{
return;
}
Color color = (Color)uiCommand.Id;
this.contentGrid.Background = new SolidColorBrush(color);
}
#endregion
#region 디스패처 타이머 틱 처리하기 - dispatcherTimer_Tick(sender, e)
/// <summary>
/// 디스패처 타이머 틱 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void dispatcherTimer_Tick(object sender, object e)
{
this.asyncOperation.Cancel();
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > UWP' 카테고리의 다른 글
[C#/UWP] FileSavePicker 클래스 : 파일 비동기 저장하기 (0) | 2016.06.01 |
---|---|
[C#/UWP] FileOpenPicker 클래스 : 파일 비동기 로드하기 (0) | 2016.06.01 |
[C#/UWP] MediaElement 엘리먼트 : 백그라운드 오디오 기능 사용하기 (0) | 2016.03.02 |
[C#/UWP] Package 클래스 : 패키지 정보 구하기 (0) | 2016.03.01 |
[C#/UWP] Application 클래스 : Suspending 이벤트 사용하기 (0) | 2016.03.01 |
[C#/UWP] MessageDialog 클래스 사용하기 (await 연산자 사용하기) (0) | 2016.02.20 |
[C#/UWP] MessageDialog 클래스 사용하기 (익명 대리자 사용) (0) | 2016.02.19 |
[C#/UWP] MessageDialog 클래스 사용하기 (0) | 2016.02.19 |
[C#/UWP] DisplayRequest 클래스 : 자동 디스플레이 끄기 방지하기 (0) | 2016.02.08 |
[C#/UWP] 클래스 계층도 표시하기 (0) | 2016.02.06 |
댓글을 달아 주세요