【问题标题】:Selecting a Notification from the Windows Phone 8.1 Action Center从 Windows Phone 8.1 操作中心选择通知
【发布时间】:2015-04-30 14:23:18
【问题描述】:

我正在像这样向设备发送 Toast 通知。

private void SendNotification(string text, string activatedargs = null) {
    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);

    XmlNodeList elements = toastXml.GetElementsByTagName("text");
    foreach(IXmlNode node in elements) {
        node.InnerText = text;
    }

    if(!string.IsNullOrEmpty(activatedargs)) {
        ((XmlElement)toastXml.SelectSingleNode("/toast")).SetAttribute("launch", activatedargs);
    }

    ToastNotification notification = new ToastNotification(toastXml);
    notification.Activated += notification_Activated;
    ToastNotificationManager.CreateToastNotifier().Show(notification);
}

如您所见,我正在为 Activated 事件添加一个回调函数。当 toast 通知弹出窗口出现在屏幕顶部时,这非常有用。但是当通知消失并且通知仅在操作中心可见时,选择通知时永远不会调用回调。该应用程序可以正常打开,但无法显示基于所选通知的信息视图。

如果我发送了三个 toast 通知,“A”、“B”和“C”。这三个通知列在我的应用名称下方的操作中心中。当专门点击通知“B”时,如何将应用打开到专门与“B”相关的视图?

【问题讨论】:

标签: visual-studio windows-phone-8.1


【解决方案1】:

您应该将activatedargs 设置为包含标识“A”、“B”或“C”。

activatedargs = "B"

然后在 App.xaml.cs 中,您可以获得标识并基于此,导航到正确的视图

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    string launchString = launchEventArgs.Arguments;
    if (!String.IsNullOrEmpty(launchString))
    {
        // Get the identification and navigate to correct view
        switch(launchString)
        {
            case "B": NavigateToViewModel<BViewModel>();
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多