Example #1
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            AppFrame rootFrame = Window.Current.Content as AppFrame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new AppFrame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            // Always restore state from disk.
            // To simplify, I'm going to do a bad thing and block the main thread while the disk read happens.
            // Since this happens before Window.Current.Activate is called, the splash screen should stay up and the user won't see any weird UI.
            try
            {
                Task restoreTask = restoreStateFromDisk();
                restoreTask.Wait();
            }
            catch (Exception)
            {
                // A FileNotFoundException is expected if there is no saved state file.
                // Ignore the error because we don't have telemetry hooked up yet to log it and we don't want the whole app launch cancelled.
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    Type targetPageType = TimeManager.Instance.HasMultipleModes ? typeof(MainPage) : typeof(ConfigurationPage);

                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(targetPageType, e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }
        }
Example #2
0
 public AppFrame()
 {
     this.InitializeComponent();
     _instance = this;
 }