我怎样才能创建shelltoast?

Jas*_*n94 7 c# windows-phone-8

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

只是跑步......

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

......没有任何事情发生,据我所知,它需要从一个运行ScheduledTaskAgent.但是如何在命令上运行它,并确保它只运行一次?

Jus*_*gel 24

当应用程序是前台应用程序时,您无法使用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))
        };
    }
Run Code Online (Sandbox Code Playgroud)

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

ToastPrompt控制图像