1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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<MusicalInstrument> 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<MusicalInstrument>
- {
- 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<MusicalInstrument> filteredInstruments = new List<MusicalInstrument>();
- 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<MusicalInstrument> 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; }
- }
- }
|