弹出通知对话框
1 <Grid> 2 <Button 3 Content="弹出通知" 4 Click="Button_Click"/> 5 </Grid>
1 private async void Button_Click(object sender, RoutedEventArgs e) 2 { 3 ////创建对话框对象 4 //MessageDialog dialog = new MessageDialog("吐司通知"); 5 ////展示对话框 6 //await dialog.ShowAsync(); 7 //少用,就像网页中不要使用alert一样 8 await new MessageDialog("弹出对话框").ShowAsync(); 9 }
吐司通知
1 <Grid> 2 <Button 3 Content="吐司通知" 4 Click="Button_Click_1"/> 5 </Grid>
1 private async void Button_Click_1(object sender, RoutedEventArgs e) 2 { 3 //获取基本吐司模版 4 var toastTmpl = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); 5 //填充模版占位符 6 var textNode = toastTmpl.GetElementsByTagName("text").FirstOrDefault(); 7 if (textNode == null) 8 { 9 await new Windows.UI.Popups.MessageDialog("shit").ShowAsync(); 10 return; 11 } 12 //设置innerText 13 textNode.InnerText = "Hello"; 14 //创建一个吐司通知对象 15 var toastNotification = new ToastNotification(toastTmpl); 16 //展示吐司通知 17 //展示吐司通知需要一个展示对象 18 ToastNotificationManager.CreateToastNotifier().Show(toastNotification); 19 }
时间: 2024-10-11 17:28:20