问题描述
在我的应用程序中,我想通过 ShellToast
通知用户。
In my application I want to notify the user with the ShellToast
.
只需运行...
var toast = new ShellToast
{
Title = "Nom nom nom!",
Content = "More! More! Keep feeding me!",
};
toast.Show();
...什么都不会发生,据我所知,它需要从<$ c运行$ c> ScheduledTaskAgent 。但是,如何在命令上运行它,并确保它只运行一次?
...makes nothing happen, and as I understand it needs to be run from a ScheduledTaskAgent
. But how do I run this on command, and make sure it only run once?
推荐答案
该应用程序是前台应用程序。
You can't use a ShellToast while the app is the foreground app. It's meant to be invoked from a background service while the app isn't the foreground app.
如果要使用类似于ShellToast的UX,请使用 ToastPrompt控件。这是一个显示代码用法的代码段:
If you want to have a UX similar to that of ShellToast use the Coding4fun toolkit ToastPrompt control. Here's a code snippet showing how to use it:
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))
};
}
运行此代码段显示以下内容:
Running this code snippet shows the following:
这篇关于如何制作贝壳吐司?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!