我怎样才能创建shelltoast?

在我的应用程序中,我想通过ShellToast通知用户。

只是跑步……

 var toast = new ShellToast { Title = "Nom nom nom!", Content = "More! More! Keep feeding me!", }; toast.Show(); 

……什么都不会发生,据我所知,它需要从ScheduledTaskAgent运行。 但是如何在命令上运行它,并确保它只运行一次?

当应用程序是前台应用程序时,您无法使用ShellToast。 当应用程序不是前台应用程序时,它意味着从后台服务调用。

如果您想拥有类似于ShellToast的UX,请使用Coding4fun工具包 ToastPrompt控件。 这是一个代码片段,展示了如何使用它:

  private void ToastWrapWithImgAndTitleClick(object sender, RoutedEventArgs e) { var toast = GetToastWithImgAndTitle(); toast.TextWrapping = TextWrapping.Wrap; toast.Show(); } private static ToastPrompt GetToastWithImgAndTitle() { return new ToastPrompt { Title = "With Image", TextOrientation = System.Windows.Controls.Orientation.Vertical, Message = LongText, ImageSource = new BitmapImage(new Uri("../../ApplicationIcon.png", UriKind.RelativeOrAbsolute)) }; } 

运行此代码段会显示以下内容:

ToastPrompt控制图像

只是一个小小的更新:当应用程序处于前台时使用ShellToast ,现在可以使用Windows Phone 8 Update 3.但是,它们会被其他活动(如电话或锁定屏幕)遮挡。 资源