private void AddData(object sender, RoutedEventArgs e) { dataTotal += 1; buttonTotal += 1; Button NewButton = new Button() { Content = "Sample" + buttonTotal, FontSize = 60, FontFamily = new FontFamily("Arial"), Background = null, Width = 465, Height = 87, HorizontalAlignment = HorizontalAlignment.Center }; // ※補足 NewButton.Click += ShowPoints -> ボタンにクリックイベントを追加するやつ NewButton.Click += ShowPoints; NewButton.HorizontalAlignment = HorizontalAlignment.Center; RelativePanel.SetAlignHorizontalCenterWith(NewButton, sender); Button addbutton = Add; NameList.Children.Remove(Add); NameList.Children.Add(NewButton); NameList.Children.Add(addbutton); Points playerData = new Points(1, 1, dataTotal); string playername = NewButton.Content.ToString(); DictionaryManager.setPlayerData(playername, playerData); if (EditOnce == false) { EditOnce = true; } }
private void LoadPlayerData() { ApplicationDataContainer database = ApplicationData.Current.LocalSettings; var playerContainer = database.Containers["key"]; // ※補足 foreach (string mcid in sortList()) -> データの中にある全てのMCIDを取得する foreach (string mcid in sortList()) { // なぜかデータからnullデータが出てしまうため、回避策としてreturnで返している if (mcid == null) { return; } bool mcidCondition = !mcid.Equals("Sample") && !mcid.Equals("Add"); if (mcidCondition) { try { Button button = new Button { Content = mcid, FontSize = 60, FontFamily = new FontFamily("Arial"), Background = null, Width = 465, Height = 87, HorizontalAlignment = HorizontalAlignment.Center }; // ※補足 button.Click += ShowPoints -> ボタンにクリックイベントを追加 button.Click += ShowPoints; dataTotal = countKeys() - 1; buttonTotal = countKeys(); Button addbutton = Add; // 一度Addボタンを付けなおして位置を直す NameList.Children.Remove(Add); NameList.Children.Add(button); NameList.Children.Add(addbutton); RelativePanel.SetAlignHorizontalCenterWith(button, addbutton); ApplicationDataCompositeValue playerdatafromdatabase = getPlayerData(mcid); int scpoint = (int)playerdatafromdatabase["SC"]; int contributionpoint = (int)playerdatafromdatabase["Contribution"]; int id = (int)playerdatafromdatabase["ID"]; Points data = new Points(scpoint, contributionpoint, id); DictionaryManager.setPlayerData(button.Content.ToString(), data); } catch (Exception e) { return; } } } }