CategoryPage.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // ----------------------------------------------------------------------------------
  2. // Microsoft Developer & Platform Evangelism
  3. //
  4. // Copyright (c) Microsoft Corporation. All rights reserved.
  5. //
  6. // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  7. // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
  8. // OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  9. // ----------------------------------------------------------------------------------
  10. // The example companies, organizations, products, domain names,
  11. // e-mail addresses, logos, people, places, and events depicted
  12. // herein are fictitious. No association with any real company,
  13. // organization, product, domain name, email address, logo, person,
  14. // places, or events is intended or should be inferred.
  15. // ----------------------------------------------------------------------------------
  16. using System;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Navigation;
  20. namespace WindowsPhoneRecipes
  21. {
  22. public partial class CategoryPage
  23. {
  24. public string Category { get; set; }
  25. public CategoryPage()
  26. {
  27. InitializeComponent();
  28. WindowsPhoneRecipes.Logger.Instance.AddLine();
  29. }
  30. private void btnNext_Click(object sender, RoutedEventArgs e)
  31. {
  32. // Navigate to the new page
  33. NavigationService.Navigate(new Uri("/ItemPage.xaml?cat=" + Category + "&item=" + (sender as Button).Name.Substring(7), UriKind.Relative));
  34. }
  35. private void btnMenu_Click(object sender, RoutedEventArgs e)
  36. {
  37. NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
  38. }
  39. private void btnCategoryList_Click(object sender, RoutedEventArgs e)
  40. {
  41. NavigationService.Navigate(new Uri("/CategoriesListingPage.xaml", UriKind.Relative));
  42. }
  43. // When page is navigated to, set data context
  44. protected override void OnNavigatedTo(NavigationEventArgs e)
  45. {
  46. base.OnNavigatedTo(e);
  47. WindowsPhoneRecipes.Logger.Instance.AddLine();
  48. Category = this.NavigationContext.QueryString["cat"];
  49. if (DataContext == null)
  50. this.DataContext = this;
  51. //simulate a big load that you want to avoid during recursive back navigation
  52. if (NonLinearNavigationService.Instance.IsRecursiveBackNavigation == true)
  53. {
  54. WindowsPhoneRecipes.Logger.Instance.AddLine("IsRecursiveBackNavigation = true");
  55. return;
  56. }
  57. //else
  58. /*
  59. * DO WORK HERE - like animation, data biding, and so on...
  60. */
  61. this.ApplicationBar.IsVisible = true;
  62. //simulate large UI blocking work - that should be avoided all togerher
  63. //System.Threading.Thread.Sleep(5000);
  64. }
  65. // FOR DEBUGGING ONLY!
  66. //static int x = 0;
  67. protected override void OnNavigatedFrom(NavigationEventArgs e)
  68. {
  69. base.OnNavigatedFrom(e);
  70. WindowsPhoneRecipes.Logger.Instance.AddLine();
  71. // on navigating away from the page, hide the appbar so we dont see it if we are recursive back
  72. this.ApplicationBar.IsVisible = false;
  73. // FOR DEBUGGING only! Simualte user canceling nav event during recursive back
  74. //if (x == 0)
  75. //{
  76. // x++;
  77. //}
  78. //else
  79. //{
  80. // //for debuging user canceling navigation
  81. // // e.Cancel = true;
  82. //}
  83. }
  84. protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
  85. {
  86. base.OnBackKeyPress(e);
  87. // due to a bug, BackKey doesnt route navigation events so we handle it
  88. if (NavigationService.CanGoBack)
  89. {
  90. e.Cancel = true;
  91. NavigationService.GoBack();
  92. }
  93. }
  94. }
  95. }