■ MessageDialog 클래스를 사용하는 방법을 보여준다. (익명 대리자 사용)
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<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> |
▶ MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
using Windows.Foundation; using Windows.UI; using Windows.UI.Core; 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 { //////////////////////////////////////////////////////////////////////////////////////////////////// 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 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 )); IAsyncOperation<IUICommand> asyncOperation = messageDialog.ShowAsync(); asyncOperation.Completed = (asyncInfo, asyncStatus) => { IUICommand uiCommand = asyncInfo.GetResults(); Color color = (Color)uiCommand.Id; IAsyncAction asyncAction = this.Dispatcher.RunAsync ( CoreDispatcherPriority.Normal, () => { this.contentGrid.Background = new SolidColorBrush(color); } ); }; } #endregion } } |