Тайлбар байхгүй

ebakhtin ac9984eec4 first 6 сар өмнө
.vs ac9984eec4 first 6 сар өмнө
Model ac9984eec4 first 6 сар өмнө
assets ac9984eec4 first 6 сар өмнө
bin ac9984eec4 first 6 сар өмнө
img ac9984eec4 first 6 сар өмнө
obj ac9984eec4 first 6 сар өмнө
App.xaml ac9984eec4 first 6 сар өмнө
App.xaml.cs ac9984eec4 first 6 сар өмнө
AssemblyInfo.cs ac9984eec4 first 6 сар өмнө
MainWindow.xaml ac9984eec4 first 6 сар өмнө
MainWindow.xaml.cs ac9984eec4 first 6 сар өмнө
readme.md ac9984eec4 first 6 сар өмнө
wpf_search_sort.csproj ac9984eec4 first 6 сар өмнө
wpf_search_sort.csproj.user ac9984eec4 first 6 сар өмнө
wpf_search_sort.sln ac9984eec4 first 6 сар өмнө

readme.md

Поиск, сортировка

XAML:

...
            <Label 
                Content="Поиск" 
                VerticalAlignment="Center"/>
            <TextBox
                Width="180"
                VerticalAlignment="Center"
                x:Name="SearchFilterTextBox"
                KeyUp="SearchFilterTextBox_KeyUp"/>

            <Label 
                Content="Цена:" 
                VerticalAlignment="Center"/>
            <RadioButton
                GroupName="Price"
                Tag="1"
                Content="по возрастанию"
                IsChecked="True"
                Checked="RadioButton_Checked"
                VerticalAlignment="Center"/>
            <RadioButton
                GroupName="Price"
                Tag="2"
                Content="по убыванию"
                Checked="RadioButton_Checked"
                VerticalAlignment="Center"/>
...

C#:

...
public IEnumerable<Product> ProductList
        {
            get
            {
                var res = _productList;
                res = _productList
                    .Where(p =>(selectedCategory == "Все категории" || p.Category == selectedCategory))
                    .Where(p =>(selectedPrice == null || (p.Price>=selectedPrice.priceFrom && p.Price<selectedPrice.priceTo)))
                    .Where(p =>(selectedCompany == "Все компании" || p.Company == selectedCompany));

                if (searchFilter != "")
                    res = res.Where(c => c.Title.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0);

                if (sortAsc) res = res.OrderBy(p => p.Price);
                else res = res.OrderByDescending(p => p.Price);

                return res;
            }
            set
            {
                _productList = value;
            }
        }
...
...
        private string searchFilter = "";
        private bool sortAsc = true;

        
        private void SearchFilterTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            searchFilter = SearchFilterTextBox.Text;
            Invalidate();
        }

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            sortAsc = (sender as RadioButton).Tag.ToString() == "1";
            Invalidate();
        }
...

Результат: