/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="Common.NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { string launchString = (string)e.NavigationParameter; if (!string.IsNullOrEmpty(launchString)) { var arguments = JsonConvert.DeserializeObject<ToastNotificationArgs>(launchString); if (arguments != null && arguments.openBookmarks) { var bookmarkCommand = new NavigateToBookmarksCommand(); bookmarkCommand.Execute(null); return; } if (arguments != null && arguments.openPrivateMessages) { var bookmarkCommand = new NavigateToPrivateMessageListPageCommand(); bookmarkCommand.Execute(null); return; } if (arguments != null && arguments.openForum) { var jumpCommand = new NavigateToThreadListPageCommandViaJumplist(); jumpCommand.Execute(arguments.forumId); return; } if (arguments != null && arguments.threadId > 0) { var bookmarkCommand = new NavigateToBookmarksCommand(); bookmarkCommand.Execute(arguments.threadId); return; } var forumEntity = JsonConvert.DeserializeObject<ForumEntity>(launchString); if (forumEntity != null) { var navigateCommand = new NavigateToThreadListPageCommandViaTile(); navigateCommand.Execute(forumEntity); } } }
async protected override void OnActivated(IActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { CreateRootFrame(); if (!RootFrame.Navigate(typeof(MainPage))) { throw new Exception("Failed to create initial page"); } Window.Current.Activate(); } if (args.Kind == ActivationKind.Launch) { var toastArgs = args as LaunchActivatedEventArgs; if (toastArgs == null) return; var arguments = JsonConvert.DeserializeObject<ToastNotificationArgs>(toastArgs.Arguments); if (arguments.openBookmarks) { var bookmarkCommand = new NavigateToBookmarksCommand(); bookmarkCommand.Execute(null); return; } if (arguments != null && arguments.openPrivateMessages) { var openPms = new NavigateToPrivateMessageListPageCommand(); openPms.Execute(null); return; } } //Find out if this is activated from a toast; if (args.Kind == ActivationKind.ToastNotification) { //Get the pre-defined arguments and user inputs from the eventargs; var toastArgs = args as ToastNotificationActivatedEventArgs; if (toastArgs == null) return; var arguments = JsonConvert.DeserializeObject<ToastNotificationArgs>(toastArgs.Argument); if (arguments != null && arguments.threadId > 0) { var bookmarkCommand = new NavigateToBookmarksCommand(); bookmarkCommand.Execute(arguments.threadId); return; } var forumEntity = JsonConvert.DeserializeObject<ForumEntity>(toastArgs.Argument); if (forumEntity != null) { var navigateCommand = new NavigateToThreadListPageCommandViaTile(); navigateCommand.Execute(forumEntity); } } // Cortana if (args.Kind == ActivationKind.VoiceCommand) { var commandArgs = args as VoiceCommandActivatedEventArgs; HandleVoiceRequest(commandArgs); } if (args.Kind == ActivationKind.Protocol) { var commandArgs = args as ProtocolActivatedEventArgs; Windows.Foundation.WwwFormUrlDecoder decoder = new Windows.Foundation.WwwFormUrlDecoder(commandArgs.Uri.Query); var destination = decoder.GetFirstValueByName("LaunchContext"); var jsonTest = WebUtility.UrlDecode(destination); var arguments = JsonConvert.DeserializeObject<ToastNotificationArgs>(jsonTest); if (arguments != null && arguments.threadId > 0) { var bookmarkCommand = new NavigateToBookmarksCommand(); bookmarkCommand.Execute(arguments.threadId); return; } if (arguments != null && arguments.openPrivateMessages) { var openPms = new NavigateToPrivateMessageListPageCommand(); openPms.Execute(null); return; } var forumEntity = JsonConvert.DeserializeObject<ForumEntity>(jsonTest); if (forumEntity != null) { var navigateCommand = new NavigateToThreadListPageCommandViaTile(); navigateCommand.Execute(forumEntity); } } //... }