public MainWindow() { InitializeComponent(); //Add Genres using (Vasyan db = new Vasyan()) { foreach (var genre in db.Genres.ToList()) { CheckBox ch = new CheckBox(); ch.Content = genre.NameGenre; ch.Checked += CheckBox_Checked; ch.Unchecked += CheckBox_Unchecked; StackGenres.Children.Add(ch); } foreach (var prod in db.Producers.ToList()) { CheckBox ch = new CheckBox(); ch.Content = prod.NameProducer; ch.Checked += CheckBox_Checked; ch.Unchecked += CheckBox_Unchecked; StackProducers.Children.Add(ch); } } listbox1.ItemsSource = Games; }
private void CheckBox_Checked(object sender, RoutedEventArgs e) { string genre = (sender as CheckBox).Content.ToString(); if (genre == "All") { Vasyan db = new Vasyan(); foreach (Game game in db.Games.ToList()) { Games.Add(game); } } else { Vasyan db = new Vasyan(); foreach (Game game in db.Games.Where(x => x.Genre.NameGenre == genre).ToList()) { Games.Add(game); } } }
private void CheckBox_Unchecked(object sender, RoutedEventArgs e) { // Games.Clear(); string genre = (sender as CheckBox).Content.ToString(); if (genre == "All") { //Vasyan db = new Vasyan(); //foreach (Game game in db.Games.ToList()) //{ // Games.Add(game); //} } else { Vasyan db = new Vasyan(); foreach (Game game in db.Games.Where(x => x.Genre.NameGenre == genre).ToList()) { Games.Remove(Games.FirstOrDefault(x => x.Name == game.Name)); } } }