c# - 如何创建 shelltoast?

标签 c# windows-phone-8

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

只需运行...

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

...什么也没发生,据我所知,它需要从 ScheduledTaskAgent 运行。但是我如何根据命令运行它,并确保它只运行一次呢?

最佳答案

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

如果你想拥有类似于 ShellToast 的用户体验,请使用 Coding4fun toolkit 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 control with image

关于c# - 如何创建 shelltoast?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14097077/

相关文章:

javascript - 通过 Ajax 将对象数组 (Javascript) 转换为 C#

c# - 重命名现有文件名

c++ - 我可以使用 Visual Studio 2015 创建 Windows Phone 8 应用程序吗?

windows-phone-7 - 将地理坐标分配给图钉

windows-phone-8 - 应用程序在模拟器上运行但在电话WP8上崩溃

c# - OxyPlot - 如何删除轴

c# - CQRS 中的验证和同步命令

c# - 通用/类型安全的 ICommand 实现?

c# - Windows Phone 8 map 控件 - 如何获取 map 边界

c# - 导航和重新实例化页面/ View 模型构造函数