public void scrollIntoNewPlayer(Player player)
 {
     PlayersListView.ScrollIntoView(player);
 }
Ejemplo n.º 2
0
        private async void AddPlayerAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            // show dialog where new players are added
            ContentDialogResult result = await addPlayerDialog.ShowAsync();
            if (result == ContentDialogResult.Primary)
            {
                // add new player to the view model
                PlayerGroup group = this.DefaultViewModel[PlayerGroupName] as PlayerGroup;
                
                Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

                int nextPlayerId = 0;
                // check next player id from settings and increment it
                if (localSettings.Values.ContainsKey(NEXT_PLAYER_ID))
                {
                    nextPlayerId = (int)localSettings.Values[NEXT_PLAYER_ID];
                    localSettings.Values[NEXT_PLAYER_ID] = (int)localSettings.Values[NEXT_PLAYER_ID] + 1;
                }
                else
                {
                    localSettings.Values[NEXT_PLAYER_ID] = 0;
                }

                int puttRating = await ratingCalculator.PlayerRating(addPlayerDialog.GetPlayerName());
                int totalGamesPlayed = await ratingCalculator.GamesPlayed(addPlayerDialog.GetPlayerName(), true);

                Debug.WriteLine("PuttRating: " + puttRating + " gamesPlayed: " + totalGamesPlayed);

                // create new player and add it to the view model
                Player newPlayer = new Player(nextPlayerId.ToString(), addPlayerDialog.GetPlayerName(), 
                                              totalGamesPlayed, puttRating); 
                group.Players.Add(newPlayer);

                //select new player by default
                playersListView.SelectedItems.Add(newPlayer);

                // Scroll the new item into view.
                playersListView.ScrollIntoView(newPlayer);
                dataSaver.SaveAllDataToJson();                
            }
            else
            {
                // User pressed Cancel or the back arrow, do nothing
            }
        }
Ejemplo n.º 3
0
        private async void AddPlayerAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            // show dialog where new players are added
            ContentDialogResult dialogResult = await addPlayerDialog.ShowAsync();
            if (dialogResult == ContentDialogResult.Primary)
            {
                // add new player to the view model
                PlayerGroup playerGroup = this.DefaultViewModel[PlayerGroupName] as PlayerGroup;
                int nextPlayerId = 0;
                // check next player id from settings and increment it
                if (localSettings.Values.ContainsKey(NEXT_PLAYER_ID))
                {
                    nextPlayerId = (int)localSettings.Values[NEXT_PLAYER_ID];
                }
                localSettings.Values[NEXT_PLAYER_ID] = (nextPlayerId + 1);

                int puttRating = await ratingCalculator.PlayerRating(addPlayerDialog.GetPlayerName());
                int totalGamesPlayed = await ratingCalculator.GamesPlayed(addPlayerDialog.GetPlayerName(), true);
                // create new player and add it to the view model
                Player newPlayer = new Player(nextPlayerId.ToString(), addPlayerDialog.GetPlayerName(),
                                              totalGamesPlayed, puttRating);
                playerGroup.Players.Add(newPlayer);

                // Scroll the new item into view.
                dataSaver.SaveAllDataToJson();
                
                // add player to selected players localSettings
                // save selected players
                string selectedPlayers = "";
                if (localSettings.Values.ContainsKey("SelectedPlayers"))
                {
                    selectedPlayers = (string)localSettings.Values["SelectedPlayers"];
                }
                selectedPlayers = selectedPlayers + newPlayer.PlayerName + ";";
                localSettings.Values["SelectedPlayers"] = selectedPlayers;


                Debug.WriteLine("Add3");
                // ask players listView to scroll down if needed
                MainPagePivotItemPlayers p = ((PivotItem)(pivot.Items.ElementAt(4))).Content as MainPagePivotItemPlayers;
                if (p != null)
                {
                    p.scrollIntoNewPlayer(newPlayer);
                }

                Debug.WriteLine("Add4");

            }
        }