Ejemplo n.º 1
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }

            string players = "";

            if (e.PageState == null)
            {
                players = e.NavigationParameter.ToString();
            }
            else if (e.PageState.ContainsKey("Players"))
            {
                players = (string)e.PageState["Players"];
            }
            else
            {
                // we have screwed up smthing
            }

            List<string> selectedPlayers = new List<string>();

            parseParametersToList(players, ref selectedPlayers);

            // create pivot items (came pages) for each player
            for (int i = 0; i < selectedPlayers.Count; ++i)
            {
                PivotItem pivotItem = new PivotItem();
                JYLYPivotItem JYLYItem = new JYLYPivotItem();
                
                JYLYItem.PlayerCompletedGame += JYLYItem_PlayerCompletedGame;
                JYLYItem.PlayerUncompletedGame += JYLYItem_PlayerUncompletedGame;

                pivotItem.Content = JYLYItem;
                pivotItem.Header = selectedPlayers[i];
                this.pivot.Items.Add(pivotItem);
            }

            // if there was a saved state, set counters to their values

            if (e.PageState != null)
            {
                for (int i = 0; i < pivot.Items.Count; ++i)
                {
                    //Debug.WriteLine("i: " + i);
                    PivotItem item = pivot.Items[i] as PivotItem;
                    JYLYPivotItem pivotItem = item.Content as JYLYPivotItem;
                    pivotItem.setState((string)e.PageState[i.ToString()]);
                }
                if (e.PageState.ContainsKey("SelectedIndex"))
                {
                    pivot.SelectedIndex = (int)e.PageState["SelectedIndex"];
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
            {
                HardwareButtons.BackPressed += HardwareButtons_BackPressed;
            }
            // set results to the viewmodel

            //create pivot items based on the selected players
            //parse selected players from navigation parameter string or local settings to a list

            string players = "";

            // first navigation to the page
            if (e.PageState == null)
            {
                players = e.NavigationParameter.ToString();
            }
            // there is a saved state, resume
            else if (e.PageState.ContainsKey("Players"))
            {
                players = (string)e.PageState["Players"];
            }
            
            List<string> selectedPlayers = new List<string>();
            parseParametersToList(players, ref selectedPlayers);

            // create pivot items (game pages) for each player
            for (int i = 0; i < selectedPlayers.Count; ++i)
            {
                PivotItem pivotItem = new PivotItem();
                AboPivotItem cxItem = new AboPivotItem();
                pivotItem.Content = cxItem;
                pivotItem.Header = selectedPlayers[i];
                this.pivot.Items.Add(pivotItem);
            }

            // if there was a saved state, set counters to their values
            if (e.PageState != null)
            {
                for (int i = 0; i < pivot.Items.Count; ++i)
                {
                    PivotItem item = pivot.Items[i] as PivotItem;
                    AboPivotItem pivotItem = item.Content as AboPivotItem;
                    pivotItem.setState((string)e.PageState[i.ToString()]);
                }
                if (e.PageState.ContainsKey("SelectedIndex"))
                {
                    pivot.SelectedIndex = (int)e.PageState["SelectedIndex"];
                }
            }
        }