The Piece of Code

[Windows 8, C#] MessageDialog

fonch 2013. 1. 20. 13:38

Windows 8 App 을 만들 때 사용할 수 있는 경고창 입니다. 윈폼에서 MessageBox.Show, javscript 에서의 alert, confirm, prompt 라고 생각하시면 됩니다.

간단할 거라 생각했는데, 비동기 프로그램이 되면서 윈폼이나 javascript 보다는 코드가 조금 늘어난 것 같네요. 윈폼에서는 여러가지 매개변수가 있었는데 그걸 생각해보면 더 간단해 진걸까요? ㅎㅎㅎ

사용법은 우선 Windows.UI.Popups Namespaceusing으로 추가해주시구요. MessageDialog Class를 사용하시면 됩니다.

MessageDialog.Commands 를 추가하지 않을 경우에는 기본 경고창이 나타납니다. 추가한다면? 추가된 Command 버튼이 나타나게 되고, Command 를 선택했을 때 Action UICommandInvokeHandler를 이용하시면 됩니다.

 

using Windows.UI.Popups;
 
async private void ShowDialog()
{
        MessageDialog messageDialog = new MessageDialog("string content", "title");
 
        //messageDialog.Commands.Add(new UICommand("string label", UICommandInvokeHandler, "ID"));
        messageDialog.Commands.Add(new UICommand("OK", UICommandInvokeHandler, "OK"));
        messageDialog.Commands.Add(new UICommand("Cancel", UICommandInvokeHandler, "Cancel"));
 
        await messageDialog.ShowAsync();
}
 
private void UICommandInvokeHandler(IUICommand command)
{
        //Action Result
        tbContent.Text = command.Id.ToString();
}


- Command를 추가하지 않은 기본 경고창




- Command 추가 경고창


'The Piece of Code' 카테고리의 다른 글

[C#] Image Resize - Winfrom  (0) 2016.02.10
[CSS] margin, pdding 순서  (0) 2015.02.03
[javascript] 모바일 기기 구분하기  (0) 2013.02.28
[C#] StripHtml  (1) 2013.01.20
[C#] Base64 Encoding, Decoding  (0) 2012.12.07