Microsoft.Phone.Applications.UnitConverter.View.CategorySelection.OnNavigatedTo C# (CSharp) Method

OnNavigatedTo() protected method

Called when we have a page to navigated event This event is raised whenever we visit the page. This can occur for the following situations 1) Application Activation where we are tomb stoned, or we are still in memory If we have been tomb stoned, we need to read objects from the application service, and then perform any initialization on the restored objects. If we received and activation event, but we were not tomb stoned, then we actually don't need to do anything except clear the main application state flag and exit. This is because all objects are still in memory. 2) We have come from the main page of the application. To work around a known issue in the Pivot control related to applying templates to non default pivot items we can't set the Pivot Index in this function. We therefore save the desired pivot index and we will set this later
protected OnNavigatedTo ( System.Windows.Navigation.NavigationEventArgs e ) : void
e System.Windows.Navigation.NavigationEventArgs Event data.
return void
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (ApplicationState.ApplicationStartup == AppOpenState.None &&
                this.pivot.Items.Count <= 1)
            {
                // We have come from the main page of the application
                this.viewModel.AllowNavigation = false;
                this.PostNavigationToInitialize();
                CategorySelectionViewModel.SyncStateToMainPageState();
                this.requestedPivotDataSelectionIndex = 
                    CategorySelectionViewModel.GetCategoryPivotIndex(pivot);
            }
            else
            {
                // Activated event case
                if (!this.IsPageActivated)
                {
                    // We are returning to the application, but we were not tomb stoned.
                    ApplicationState.ApplicationStartup = AppOpenState.None;
                    return;
                }
                this.viewModel.AllowNavigation = false;
                ApplicationState.RetrieveAppObjects(true);
                this.PostNavigationToInitialize();
                this.requestedPivotDataSelectionIndex = 
                    ApplicationState.CategoryPageInformation.PivotSelectedIndex;
                if (this.requestedPivotDataSelectionIndex == 0)
                {
                    /* If the index is 0, we don't receive an event for the pivot item
                     * changing which will cause the pivot to not render correctly.
                     * We can set the index to 1 ( normal default) without causing any
                     * problem for the pivot control. We will then set the index to 
                     * 0 later and we should get the event to fire
                     */
                    this.viewModel.SelectedDataIndex = 1;
                }
            }

            // Reenabled buttons 
            this.viewModel.AllowNavigation = true;
            pivot.Opacity = 0;
            ApplicationState.ApplicationStartup = AppOpenState.None;
        }