这篇文章是从自己的个人网站转过来的,因为3月份个人网站就要关了
关于ShellToast,官方有这么一句话
A class for displaying a toast to the user. While the Show method can be called from any application, a toast will not be displayed if the current foreground application is the caller of the ShellToast.Show method. This means that this should primarily be used by a background agent.
也就是说如果你ShellToast.Show的时候,调用这个ShellToast的程序不能在前台运行,不然ShellToast不会显示,用下面的方法来模仿在后台显示。点击之后马上按模拟器 或者真机上的 主页按钮,过3秒 显示成功!
void showmessagebox()
{
Dispatcher.BeginInvoke(() => {
System.Threading.Thread.Sleep(3000);
ShellToast toast = new ShellToast();
toast.Title = "AnthemSword";
toast.Content = "这是一个ShellToast";
toast.Show();
toast.NavigationUri = new Uri("/xxxxx.xaml", UriKind.Relative);
});
}
private void Button_Click(object sender, RoutedEventArgs e)
{
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(showmessagebox));
th.Start();
}