Advertisement
Guest User

Untitled

a guest
Jun 29th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. public MainPage(){
  2. InitializeComponent();
  3. if (phoneAppService.State.TryGetValue("currentLanguage", out someObject))
  4. { // Yes: go on
  5. var uri = "/Pages/Page_A.xaml";
  6. this.Dispatcher.BeginInvoke(() => this.NavigationService.Navigate(new Uri(uri, UriKind.Relative)));
  7. }
  8. else
  9. { // No: select language before proceeding
  10. var uri = "/Pages/Page_B.xaml";
  11. this.Dispatcher.BeginInvoke( () => this.NavigationService.Navigate(new Uri(uri, UriKind.Relative)));
  12. }
  13. }
  14.  
  15. **// if previous page was Page_A or Page_B then exit application**
  16. protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
  17. {
  18. string sourcePage = "";
  19. if (NavigationContext.QueryString.TryGetValue("from", out sourcePage)) {
  20. if ((string.Compare(sourcePage.ToString(), "Page_A")) == 0 ? true : false) {
  21. **// EXIT APPLICATION**
  22. }
  23. if ((string.Compare(sourcePage.ToString(), "Page_B")) == 0 ? true : false) {
  24. **// EXIT APPLICATION**
  25. }
  26. }
  27. base.OnNavigatedTo(e);
  28. }
  29.  
  30. // Back Button pressed: notify MainPage so it can exit application
  31. protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
  32. {
  33. NavigationService.Navigate(new Uri(uri, UriKind.Relative));
  34. base.OnBackKeyPress(e);
  35. }
  36.  
  37. // Back Button pressed: notify MainPage so it can exit application
  38. protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
  39. {
  40. var uri = "/MainPage.xaml?from=Page_B";
  41. NavigationService.Navigate(new Uri(uri, UriKind.Relative));
  42. base.OnBackKeyPress(e);
  43. }
  44.  
  45. RootFrame.Navigated += RootFrame_Navigated;
  46.  
  47. void RootFrame_Navigated(object sender, NavigationEventArgs e)
  48. {
  49. var pageBURI = "/Pages/Page_B.xaml";
  50. var pageAURI = "/Pages/Page_A.xaml";
  51.  
  52. if ((e.Uri == pageAURI || e.Uri == pageBURI) && RootFrame.BackStack.Count() > 0)
  53. {
  54. RootFrame.RemoveBackEntry();
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement