Advertisement
Sletner91

unfinished TIMER

Feb 3rd, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. /*********THIS IS THE TIME CLASS***********/
  2. using System;
  3. using System.Windows;
  4. using System.Windows.Threading;
  5.  
  6. namespace CompiledExperience.WP7.Midnight
  7. {
  8. public partial class MainPage
  9. {
  10. private DispatcherTimer timer;
  11.  
  12. public MainPage()
  13. {
  14. InitializeComponent();
  15.  
  16. Loaded += OnLoaded;
  17. }
  18.  
  19. private void OnLoaded(object sender, RoutedEventArgs e)
  20. {
  21. timer = new DispatcherTimer
  22. {
  23. Interval = TimeSpan.FromSeconds(1)
  24. };
  25.  
  26. timer.Tick += OnTick;
  27.  
  28. timer.Start();
  29. }
  30.  
  31. private void OnTick(object sender, EventArgs e)
  32. {
  33. var midnight = DateTime.Today.AddHours(24);
  34. var timeLeft = midnight - DateTime.Now;
  35.  
  36. Countdown.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", timeLeft.Hours, timeLeft.Minutes, timeLeft.Seconds);
  37. }
  38. }
  39. }
  40.  
  41. /*************** THIS IS THE APP CLASS ******************/
  42. using System.Diagnostics;
  43. using System.Windows;
  44. using System.Windows.Navigation;
  45. using Microsoft.Phone.Controls;
  46.  
  47. namespace CompiledExperience.WP7.Midnight
  48. {
  49. public partial class App
  50. {
  51. private bool phoneApplicationInitialized;
  52.  
  53. public App()
  54. {
  55. UnhandledException += OnUnhandledException;
  56.  
  57. InitializeComponent();
  58.  
  59. InitializePhoneApplication();
  60. }
  61.  
  62. public PhoneApplicationFrame RootFrame
  63. {
  64. get; private set;
  65. }
  66.  
  67. private static void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  68. {
  69. if(Debugger.IsAttached)
  70. Debugger.Break();
  71. }
  72.  
  73. private static void OnUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
  74. {
  75. if(Debugger.IsAttached)
  76. Debugger.Break();
  77. }
  78.  
  79.  
  80. private void InitializePhoneApplication()
  81. {
  82. if(phoneApplicationInitialized)
  83. return;
  84. RootFrame = new PhoneApplicationFrame();
  85.  
  86. RootFrame.Navigated += CompleteInitializePhoneApplication;
  87. RootFrame.NavigationFailed += OnNavigationFailed;
  88.  
  89. phoneApplicationInitialized = true;
  90. }
  91.  
  92. private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
  93. {
  94. RootVisual = RootFrame;
  95.  
  96. RootFrame.Navigated -= CompleteInitializePhoneApplication;
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement