Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********THIS IS THE TIME CLASS***********/
- using System;
- using System.Windows;
- using System.Windows.Threading;
- namespace CompiledExperience.WP7.Midnight
- {
- public partial class MainPage
- {
- private DispatcherTimer timer;
- public MainPage()
- {
- InitializeComponent();
- Loaded += OnLoaded;
- }
- private void OnLoaded(object sender, RoutedEventArgs e)
- {
- timer = new DispatcherTimer
- {
- Interval = TimeSpan.FromSeconds(1)
- };
- timer.Tick += OnTick;
- timer.Start();
- }
- private void OnTick(object sender, EventArgs e)
- {
- var midnight = DateTime.Today.AddHours(24);
- var timeLeft = midnight - DateTime.Now;
- Countdown.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", timeLeft.Hours, timeLeft.Minutes, timeLeft.Seconds);
- }
- }
- }
- /*************** THIS IS THE APP CLASS ******************/
- using System.Diagnostics;
- using System.Windows;
- using System.Windows.Navigation;
- using Microsoft.Phone.Controls;
- namespace CompiledExperience.WP7.Midnight
- {
- public partial class App
- {
- private bool phoneApplicationInitialized;
- public App()
- {
- UnhandledException += OnUnhandledException;
- InitializeComponent();
- InitializePhoneApplication();
- }
- public PhoneApplicationFrame RootFrame
- {
- get; private set;
- }
- private static void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
- {
- if(Debugger.IsAttached)
- Debugger.Break();
- }
- private static void OnUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
- {
- if(Debugger.IsAttached)
- Debugger.Break();
- }
- private void InitializePhoneApplication()
- {
- if(phoneApplicationInitialized)
- return;
- RootFrame = new PhoneApplicationFrame();
- RootFrame.Navigated += CompleteInitializePhoneApplication;
- RootFrame.NavigationFailed += OnNavigationFailed;
- phoneApplicationInitialized = true;
- }
- private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
- {
- RootVisual = RootFrame;
- RootFrame.Navigated -= CompleteInitializePhoneApplication;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement