public MainPage() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainPage_Loaded); this.BackKeyPress += new EventHandler<System.ComponentModel.CancelEventArgs>(MainPage_BackKeyPress); //If the token is not found, we route to the login-page on load TryInitializeAccessToken(); bookListVM = new BookListViewModel(); this.DataContext = bookListVM; }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); string navigatedUri = e.Uri.ToString(); if (navigatedUri.Contains("from_login=true")) { //Remove login page(s) from back-stack - home should be the first page while(NavigationService.CanGoBack) NavigationService.RemoveBackEntry(); } if (viewModelsInvalidated) { //We do not restore state but refresh on reactivations bookListVM = new BookListViewModel(); booksPanoramaItem.DataContext = bookListVM; collectionsVM = new CollectionsViewModel(); collectionsPanoramaItem.DataContext = collectionsVM; viewModelsInvalidated = false; } cancel = new CancellationTokenSource(); //Load UI LoadBooksPanoramaItem(); LoadCollectionsPanoramaItem(); }