Icollectionview мульти фильтр по одному полю mvvm

Как сортировать по многим полям знаю тут мне мульти фильтр по одному полю UserId. То есть у меня 3 textboxs в них будут записаны UserId,из трех textboxs получиться 3 значения по которым должна проводиться сортировка. Например: В 3 textboxs значения такие 1,4,5 должен получить все данные с этими UserId 1,UserId 4, UserId 5.

введите сюда описание изображения

У меня получиться получить только по одному фильтру например в тех UserId 10 надо трем фильтрам. введите сюда описание изображения

MainWindowViewModel

    class MainWindowViewModel : ViewModelBase
    {
        public ObservableCollection<User> Users { get; set; }
        public ObservableCollection<Todo> Todos { get; set; }
        public ObservableCollection<Post> Posts { get; set; }
        public ObservableCollection<Сomment> Сomments { get; set; }
        public ObservableCollection<Album> Albums { get; set; }
        public ObservableCollection<Photo> Photos  { get; set; }

        public CollectionView TodosView { get; private set; }


        private int? filter;

        public int? Fileter
        {
            get { return filter; }
            set
            {
                filter = value;
                Filters();
                RaisePropertyChanged("Fileter");
            }
        }

      
        private int? filter2;

        public int? Fileter2
        {
            get { return filter2; }
            set
            {
                filter2 = value;
                RaisePropertyChanged("Fileter2");
            }
        }


        private int? filter3;

        public int? Fileter3
        {
            get { return filter3; }
            set
            {
                filter3 = value;
                RaisePropertyChanged("Fileter3");
            }
        }
        private void Filters()
        {
            TodosView.Filter = (obj) =>
            {
                if (obj is Todo Todo)
                    return Fileter == Todo.UserId;
                return false;
            };
            TodosView.Refresh();
        }


        public MainWindowViewModel()
        {
            Load();
            TodosView = (CollectionView)CollectionViewSource.GetDefaultView(Todos);
        }
        

        private void Load()
        {
            string usersjson = GetFile("https://jsonplaceholder.typicode.com/users");
            string todosjson = GetFile("https://jsonplaceholder.typicode.com/todos");
            string postsjson = GetFile("https://jsonplaceholder.typicode.com/posts");
            string commentsjson = GetFile("https://jsonplaceholder.typicode.com/comments");
            string albumsjson = GetFile("https://jsonplaceholder.typicode.com/albums");
            string photosjson = GetFile("https://jsonplaceholder.typicode.com/photos");

            Users = JsonConvert.DeserializeObject<ObservableCollection<User>>(usersjson);
            Todos = JsonConvert.DeserializeObject<ObservableCollection<Todo>>(todosjson);
            Posts= JsonConvert.DeserializeObject<ObservableCollection<Post>>(postsjson);
            Сomments= JsonConvert.DeserializeObject<ObservableCollection<Сomment>>(commentsjson);
            Albums = JsonConvert.DeserializeObject<ObservableCollection<Album>>(albumsjson);
            Photos = JsonConvert.DeserializeObject<ObservableCollection<Photo>>(photosjson);
        }

        private  string GetFile(string site)
        {
            string responseString =string.Empty;
            using (var webClient = new WebClient())
            {
                responseString = webClient.DownloadString(site);
            }
            return responseString;
        }
    }

MainWindow

<Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="64*"/>
            <RowDefinition Height="597*"/>
            <RowDefinition Height="2*"/>
        </Grid.RowDefinitions>

        <GroupBox Header="Multi-filter id" Margin="5">
            <StackPanel Margin="5" Orientation="Horizontal">
                <TextBlock Margin="10,0,0,0" Text="Filter 1:" />
                <TextBox   Text="{Binding Fileter,UpdateSourceTrigger=PropertyChanged}" MinWidth="30"  />
                <TextBlock Margin="10,0,0,0" Text="Filter 2:" />
                <TextBox  Text="{Binding Fileter2,UpdateSourceTrigger=PropertyChanged}" MinWidth="30" />
                <TextBlock Margin="10,0,0,0" Text="Filter 3:" />
                <TextBox  Text="{Binding Fileter3,UpdateSourceTrigger=PropertyChanged}" MinWidth="30" />
                <Button Margin="10,0,0,0" Content="Reset" MinWidth="50"/>
            </StackPanel>
        </GroupBox>

        <DataGrid Margin="5" Grid.Row="1" IsReadOnly="True"  ItemsSource="{Binding TodosView}" />
    </Grid>

Ответы (1 шт):

Автор решения: Vladimir

При каждом обновлении свойств вызывать метод c фильтром и делать проверку.

            private int? filter;
    
            public int? Fileter
            {
                get { return filter; }
                set
                {
                    filter = value;
                    Filters();
                    RaisePropertyChanged("Fileter");
                }
            }
    
          
            private int? filter2;
    
            public int? Fileter2
            {
                get { return filter2; }
                set
                {
                    filter2 = value;
                    Filters();
                    RaisePropertyChanged("Fileter2");
                }
            }
    
    
            private int? filter3;
    
            public int? Fileter3
            {
                get { return filter3; }
                set
                {
                    filter3 = value;
                    Filters();
                    RaisePropertyChanged("Fileter3");
                }
            }
            private void Filters()
            {
                TodosView.Filter = (obj) =>
                {
                    if (obj is Todo Todo)
                        return  Todo.UserId== Fileter || Todo.UserId == Fileter2 || Todo.UserId == Fileter3;
                    return false;
                };
                TodosView.Refresh();
            }
→ Ссылка