using System.ComponentModel; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using wpf_template.Model; namespace wpf_template { /// /// Interaction logic for MainWindow.xaml /// /// public partial class MainWindow : Window, INotifyPropertyChanged { private IEnumerable _productList; public IEnumerable ProductList { get { return _productList .Where(p =>(selectedCategory == "Все категории" || p.Category == selectedCategory)) .Where(p =>(selectedPrice == null || (p.Price>=selectedPrice.priceFrom && p.Price(selectedCompany == "Все компании" || p.Company == selectedCompany)); } set { _productList = value; } } public List CategoryList { get; set; } public List ProductPrices { get; set; } public List ProductCompanies { get; set; } string selectedCategory = ""; string selectedCompany = ""; private ProductPrice? selectedPrice = null; public MainWindow() { InitializeComponent(); DataContext = this; Globals.dataProvider = new LocalDataProvider(); ProductList = Globals.dataProvider.GetProducts(); ProductPrices = Globals.dataProvider.GetPrices().ToList(); CategoryList = Globals.dataProvider.GetCategories().ToList(); CategoryList.Insert(0, new ProductCategory { title = "Все категории" }); ProductCompanies = Globals.dataProvider.GetCompanies().ToList(); ProductCompanies.Insert(0, new ProductCompany { title = "Все компании" }); } private void ExitButton_Click(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } private void CategoryFilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedCategory = (CategoryFilterComboBox.SelectedItem as ProductCategory).title; Invalidate(); } private void PriceFilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedPrice = PriceFilterComboBox.SelectedItem as ProductPrice; Invalidate(); } private void CompanyFilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { selectedCompany = (CompanyFilterComboBox.SelectedItem as ProductCompany).title; Invalidate(); } public event PropertyChangedEventHandler PropertyChanged; private void Invalidate() { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("ProductList")); } } class Globals { public static IDataProvider dataProvider; } }