/// <summary> /// Sets up the view model. /// </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) { defaultViewModel = (TripListViewModel)this.DataContext; DefaultViewModel.SelectedTrip = null; Window.Current.CoreWindow.VisibilityChanged += CoreWindow_VisibilityChanged; }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// Resets the state of the view model by passing in the parameters provided by the /// caller. /// </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) { defaultViewModel = (TripViewModel)this.DataContext; if (e.NavigationParameter is Trip) { // Activated via selecting a trip in the main page's list of trips. DefaultViewModel.ShowTrip((Trip)e.NavigationParameter); } else if (e.NavigationParameter is TripVoiceCommand) { // look up destination, set trip. TripVoiceCommand voiceCommand = (TripVoiceCommand)e.NavigationParameter; DefaultViewModel.LoadTripFromStore(voiceCommand.destination); // artificially populate the page backstack so we have something to // go back to to get to the main page. PageStackEntry backEntry = new PageStackEntry(typeof(View.TripListView), null, null); this.Frame.BackStack.Add(backEntry); } else if(e.NavigationParameter is string) { // We've been URI Activated, possibly by a user clicking on a tile in a Cortana session, // we should see an argument like destination=<Location>. // This should handle finding all of the destinations that match, but currently it only // finds the first one. string arguments = e.NavigationParameter as string; if(arguments != null) { string[] args = arguments.Split('='); if (args.Length == 2 && args[0].ToLowerInvariant() == "destination") { DefaultViewModel.LoadTripFromStore(args[1]); // artificially populate the page backstack so we have something to // go back to to get to the main page. PageStackEntry backEntry = new PageStackEntry(typeof(View.TripListView), null, null); this.Frame.BackStack.Add(backEntry); } } } else { DefaultViewModel.NewTrip(); } }