【问题标题】:Xamarin forms win phone silverlight 8.1 Toast notifications not workingXamarin 表单 win phone silverlight 8.1 Toast 通知不起作用
【发布时间】:2016-02-17 07:33:21
【问题描述】:

我正在尝试在 Xamarin Forms、windows phone 8.1 silverlight 项目中显示 toast 通知。在 Windows Phone 项目中,我有一个创建 toast 通知的方法,但是在执行时没有任何反应。没有抛出任何错误,一切似乎都正确执行,但手机上没有任何反应。

我已经在模拟器和实际手机上对其进行了测试。到目前为止,我在网上找到的所有内容都与我所拥有的几乎相同(略有不同,但没有什么不同)。

方法中的代码如下:

private void CreateNotification(string title, string message)
{
    ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();

    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
    XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
    toastTextElements[0].AppendChild(toastXml.CreateTextNode(title));
    toastTextElements[1].AppendChild(toastXml.CreateTextNode(message));

    ToastNotification toast = new ToastNotification(toastXml);
    toast.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(5);

    toastNotifier.Show(toast);
}

任何帮助将不胜感激。

提前致谢!

【问题讨论】:

    标签: notifications xamarin.forms toast win-phone-silverlight-8.1


    【解决方案1】:

    如果您使用的是 Xamarin Forms,则有一个 NuGet 包:https://www.nuget.org/packages/Toasts.Forms.Plugin/

    它没有使用 windows phone 中的标准 toast 通知系统,但需要对其进行扩展。

    至于显示 Toast 通知,您是否在 Package.appxmanifest 中将 Toast Capable 设置为 Yes?

    【讨论】:

    • 非常感谢,我错过了 Toast Capable 属性! (我之前曾寻找过这处房产,但似乎我完全错过了它,因为你再次提到它,我决定再看一遍,并惊讶它就在那里!)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 2016-06-05
    • 1970-01-01
    • 2020-06-14
    相关资源
    最近更新 更多