注:本文由BeyondVincent(破船)原创首发
转载请注明出处:BeyondVincent(破船)@DevDiv.com
更多内容请查看下面的帖子
[DevDiv原创]Windows 8 开发Step by Step
最近有开发者问起Windows Store app中对话框如何使用,以及如何自定义对话框。在这篇文章中,我介绍Windows Store app中自带的对话框MessageDialog,实际上非常简单。在下一篇文章中,我将介绍如何使用Popup自定义对话框。
private async void Button_Click_1(object sender, RoutedEventArgs e) { MessageDialog dialog = new MessageDialog("你好,这里是Windows Store app学习之旅!"); dialog.Title = "温馨提示"; await dialog.ShowAsync(); }
private async void Button_Click_2(object sender, RoutedEventArgs e) { MessageDialog dialog = new MessageDialog("你好,欢迎访问移动技术开发社区:DevDiv.com"); dialog.Title = "温馨提示"; dialog.Commands.Add(new UICommand("DevDiv主页", command => { //在这里做相关操作 OpenDevDiv("http://www.DevDiv.com"); })); dialog.Commands.Add(new UICommand("关闭", command => { //在这里做相关操作 })); await dialog.ShowAsync(); }
private async void Button_Click_3(object sender, RoutedEventArgs e) { MessageDialog dialog = new MessageDialog("你好,欢迎访问移动技术开发社区:DevDiv.com"); dialog.Title = "温馨提示"; dialog.Commands.Add(new UICommand("DevDiv主页", null, 0)); dialog.Commands.Add(new UICommand("DevDiv论坛", null, 1)); dialog.Commands.Add(new UICommand("关闭", null, 2)); var command = await dialog.ShowAsync(); if (Convert.ToInt32(command.Id) == 0) { OpenDevDiv("http://www.DevDiv.com"); } else if (Convert.ToInt32(command.Id) == 0) { OpenDevDiv("http://www.devdiv.com/forum.php"); } else { // do nothing } }
private async void Button_Click_4(object sender, RoutedEventArgs e) { MessageDialog dialog = new MessageDialog("你好,欢迎访问移动技术开发社区:DevDiv.com"); dialog.Title = "温馨提示"; dialog.Commands.Add(new UICommand("DevDiv主页", null, 0)); dialog.Commands.Add(new UICommand("DevDiv论坛", null, 1)); dialog.Commands.Add(new UICommand("关闭", null, 2)); dialog.DefaultCommandIndex = 0; dialog.CancelCommandIndex = 2; var command = await dialog.ShowAsync(); if (Convert.ToInt32(command.Id) == 0) { //OpenDevDiv("http://www.DevDiv.com"); } else if (Convert.ToInt32(command.Id) == 1) { OpenDevDiv("http://www.devdiv.com/forum.php"); } else { // do nothing } }