Visual studio 从Windows Phone 8.1操作中心选择通知

Visual studio 从Windows Phone 8.1操作中心选择通知,visual-studio,windows-phone-8.1,Visual Studio,Windows Phone 8.1,我正在像这样向设备发送Toast通知 private void SendNotification(string text, string activatedargs = null) { XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); XmlNodeList elements = toastXml.GetElementsByTagN

我正在像这样向设备发送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);
}
如您所见,我为激活的事件添加了一个回调函数。当toast通知弹出窗口出现在屏幕顶部时,这非常有效。但是,当通知逐渐消失,并且通知仅在操作中心可见时,在选择通知时将永远不会调用回调。应用程序打开得很好,但不会显示基于所选通知的信息


因此,如果我已经发送了三个吐司通知,“A”、“B”和“C”。这三个通知列在我的应用程序名称下面的行动中心中。当点击通知“B”时,如何打开应用程序以查看与“B”相关的特定视图?

您应该将
激活的args
设置为包含标识“a”、“B”或“C”

然后,在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>();
        }
    }
}
protectedoverride void OnLaunched(启动ActivatedEventargs参数)
{
string launchString=launchEventArgs.Arguments;
如果(!String.IsNullOrEmpty(launchString))
{
//获取标识并导航到正确的视图
开关(启动字符串)
{
案例“B”:NavigateToViewModel();
}
}
}
请参阅此链接:此链接必须对您有所帮助。
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>();
        }
    }
}