### MainWindow ``` using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using WpfApp2; using WpfApp3.Class; namespace WpfApp3 { public partial class MainWindow : Window { private InstrumentDataManager dataManager; private InstrumentFilter filter; private string searchFilter = ""; private bool sortAsc = true; public MainWindow() { InitializeComponent(); dataManager = new InstrumentDataManager(); filter = new InstrumentFilter(); FilterComboBox.Items.Add("Все"); FilterComboBox.Items.Add("Клавишные"); FilterComboBox.Items.Add("Струнные"); FilterComboBox.Items.Add("Ударные"); FilterComboBox.SelectedIndex = 0; UpdateInstrumentList(dataManager.GetInstruments()); } private void FilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { string selectedFilter = (string)FilterComboBox.SelectedItem; if (selectedFilter == "Все") { UpdateInstrumentList(filter.FilterAll(dataManager.GetInstruments())); } else { UpdateInstrumentList(filter.FilterByType(dataManager.GetInstruments(), selectedFilter)); } } private void SearchFilter_KeyUp(object sender, KeyEventArgs e) { searchFilter = SearchFilterTextBox.Text; UpdateInstrumentList(dataManager.GetInstruments()); } private void RadioButtonAsc_Checked(object sender, RoutedEventArgs e) { sortAsc = true; UpdateInstrumentList(dataManager.GetInstruments()); } private void RadioButtonDesc_Checked(object sender, RoutedEventArgs e) { sortAsc = false; UpdateInstrumentList(dataManager.GetInstruments()); } private void UpdateInstrumentList(List instrumentsToDisplay) { if (!string.IsNullOrEmpty(searchFilter)) { instrumentsToDisplay = instrumentsToDisplay.Where(i => i.Name.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0 || i.Type.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >=0 || i.Brand.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0).ToList(); } if (sortAsc) { instrumentsToDisplay = instrumentsToDisplay.OrderBy(i => i.Price).ToList(); } else { instrumentsToDisplay = instrumentsToDisplay.OrderByDescending(i => i.Price).ToList(); } InstrumentListView.ItemsSource = instrumentsToDisplay; } private void ExitButton_Click(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } } } ### Filter ``` using System.Collections.Generic; using System.Linq; using WpfApp3.Class; namespace WpfApp2 { class InstrumentFilter { public List FilterByType(List instruments, string type) { return instruments.Where(i => i.Type == type).ToList(); } public List FilterAll(List instruments) { return instruments; } } } ``` ### Manager ``` using System.Collections.Generic; using WpfApp3.Class; using System.IO; using CsvHelper; using CsvHelper.Configuration; using System.Linq; using System.Globalization; namespace WpfApp3 { class InstrumentDataManager { private List instruments; public InstrumentDataManager() { 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 }, }; using (var reader = new StreamReader("./data.csv")) using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { instruments = csv.GetRecords().ToList(); } } public List GetInstruments() { return instruments; } } } ``` ### MusicalInsrument ``` using System.Collections.Generic; using WpfApp3.Class; using System.IO; using CsvHelper; using CsvHelper.Configuration; using System.Linq; using System.Globalization; namespace WpfApp3 { class InstrumentDataManager { private List instruments; public InstrumentDataManager() { 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 }, }; CsvConfiguration configuration = new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = ",", HasHeaderRecord = true, IgnoreBlankLines = true }; using (var reader = new StreamReader("./data.csv")) using (var csv = new CsvReader(reader, configuration)) { instruments = csv.GetRecords().ToList(); } } public List GetInstruments() { return instruments; } } } ``` ```