MainWindow.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.ComponentModel;
  2. using System.Text;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. using System.Windows.Documents;
  7. using System.Windows.Input;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Imaging;
  10. using System.Windows.Navigation;
  11. using System.Windows.Shapes;
  12. using exam.Model;
  13. namespace exam
  14. {
  15. /// <summary>
  16. /// Interaction logic for MainWindow.xaml
  17. /// </summary>
  18. public partial class MainWindow : Window, INotifyPropertyChanged
  19. {
  20. private IEnumerable<Clothes> _clothes = null;
  21. public List <ClothesCategory> ClothesCategoriesList { get; set; }
  22. public string selectedCategory = "";
  23. public IEnumerable<Clothes> ClothesList
  24. {
  25. get
  26. {
  27. return _clothes
  28. .Where(c => (selectedCategory == "Все категории" || c.Category == selectedCategory));
  29. }
  30. set
  31. {
  32. _clothes = value;
  33. }
  34. }
  35. public MainWindow()
  36. {
  37. InitializeComponent();
  38. DataContext = this;
  39. Globals.dataProvider = new JsonDataProvider();
  40. ClothesList = Globals.dataProvider.GetClothes();
  41. ClothesCategoriesList = Globals.dataProvider.GetClothesCategories().ToList();
  42. ClothesCategoriesList.Insert(0, new ClothesCategory { Title = "Все категории" });
  43. }
  44. private void ExitButton_Click(object sender, RoutedEventArgs e)
  45. {
  46. Application.Current.Shutdown();
  47. }
  48. private void CategoryFilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  49. {
  50. selectedCategory = (CategoryFilterComboBox.SelectedItem as ClothesCategory).Title;
  51. Invalidate();
  52. }
  53. public event PropertyChangedEventHandler PropertyChanged;
  54. private void Invalidate()
  55. {
  56. if (PropertyChanged != null)
  57. PropertyChanged(this, new PropertyChangedEventArgs("ClothesList"));
  58. }
  59. }
  60. }