using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; namespace WpfApp2 { public partial class MainWindow : Window { private List instruments; public MainWindow() { InitializeComponent(); InitializeData(); FilterComboBox.Items.Add("Все"); FilterComboBox.Items.Add("Клавишные"); FilterComboBox.Items.Add("Струнные"); FilterComboBox.Items.Add("Ударные"); FilterComboBox.SelectedIndex = 0; UpdateInstrumentList(instruments); } private void InitializeData() { instruments = new List { new MusicalInstrument { Name = "Гитара", Type = "Струнные", Price = 300 }, new MusicalInstrument { Name = "Барабаны", Type = "Ударные", Price = 500 }, new MusicalInstrument { Name = "Фортепиано", Type = "Клавишные", Price = 1000 }, new MusicalInstrument { Name = "Скрипка", Type = "Струнные", Price = 400 }, new MusicalInstrument { Name = "Труба", Type = "Медные", Price = 600 }, }; } private void FilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { string selectedFilter = (string)FilterComboBox.SelectedItem; List filteredInstruments = new List(); switch (selectedFilter) { case "Все": filteredInstruments = instruments; break; case "Клавишные": filteredInstruments = instruments.Where(i => i.Type == "Клавишные").ToList(); break; case "Струнные": filteredInstruments = instruments.Where(i => i.Type == "Струнные").ToList(); break; case "Ударные": filteredInstruments = instruments.Where(i => i.Type == "Ударные").ToList(); break; } UpdateInstrumentList(filteredInstruments); } private void UpdateInstrumentList(List instrumentsToDisplay) { InstrumentListView.ItemsSource = instrumentsToDisplay; } } class MusicalInstrument { public string Name { get; set; } public string Type { get; set; } public string Brand { get; set; } public double Price { get; set; } } }