public MainWindow() // startläget, kollar om jag har någon startad fil om ja, visas dessa, annars skapas nya objekt { InitializeComponent(); if (File.Exists(fileName)) { candyCalculator = (CandyCalculator)FileOperations.Deserialize(fileName); } else { candyCalculator = new CandyCalculator(); person = new Person(); } ListBox.ItemsSource = null; ListBox.ItemsSource = candyCalculator.GetPeople(); }
private void Fördelagodisknapp_Click(object sender, RoutedEventArgs e) { peoplelist = candyCalculator.GetPeople(); List1.Items.Clear(); if (Åldersknapp.IsChecked == true) { peoplelist = candyCalculator.DivideCandyByAge(peoplelist); } if (Bokstavsordningsknapp.IsChecked == true) { peoplelist = candyCalculator.DivideCandyByName(peoplelist); } candyCalculator.DivideCandy(peoplelist, double.Parse(Antalgodisbox.Text)); for (int i = 0; i < peoplelist.Count; i++) { List1.Items.Add($"{peoplelist[i].Firstname} ({peoplelist[i].Age} år): ---> {(peoplelist[i].Candies)} godisar"); } }
private void NewPerson_Click(object sender, RoutedEventArgs e) { Person person = new Person() { Name = Name.Text, Age = Convert.ToInt32(Age.Text) }; cHandler.AddPerson(person); cOriginalList.Add(person); PersonList.ItemsSource = null; PersonList.ItemsSource = cHandler.GetPeople(); }