public MainPage() { this.InitializeComponent(); App.RootFrame = MainFrame; App.RootFrame.Navigated += RootFrameOnNavigated; Locator.ViewModels.MainPageVm.MainPageSplitView = Splitter; if (_localSettings.Values.ContainsKey(Constants.BookmarkStartup)) { if ((bool) _localSettings.Values[Constants.BookmarkStartup]) { var test = new NavigateToBookmarksCommand(); test.Execute(null); } else { var test2 = new NavigateToMainForumsPage(); test2.Execute(null); } } else { var test3 = new NavigateToMainForumsPage(); test3.Execute(null); } this.navigationHelper = new NavigationHelper(this); this.navigationHelper.LoadState += navigationHelper_LoadState; this.navigationHelper.SaveState += navigationHelper_SaveState; }
/// <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); } } //... }
public void HandleVoiceRequest(VoiceCommandActivatedEventArgs commandArgs) { Windows.Media.SpeechRecognition.SpeechRecognitionResult speechRecognitionResult = commandArgs.Result; // Get the name of the voice command and the text spoken. See AdventureWorksCommands.xml for // the <Command> tags this can be filled with. string voiceCommandName = speechRecognitionResult.RulePath[0]; string textSpoken = speechRecognitionResult.Text; // The commandMode is either "voice" or "text", and it indictes how the voice command // was entered by the user. // Apps should respect "text" mode by providing feedback in silent form. string commandMode = this.SemanticInterpretation("commandMode", speechRecognitionResult); switch (voiceCommandName) { case "openBookmarks": var bookmarkCommand = new NavigateToBookmarksCommand(); bookmarkCommand.Execute(null); break; case "openPrivateMessages": var pmCommand = new NavigateToPrivateMessageListPageCommand(); pmCommand.Execute(null); break; case "lowtaxIsAJerk": var lowtaxCommand = new NavigateToNewPrivateMessagePageLowtaxCommand(); lowtaxCommand.Execute(null); break; default: break; } }