Z
Z
Zulkund2017-02-25 21:33:44
WPF
Zulkund, 2017-02-25 21:33:44

How to create filtering on bound collection in WPF?

Good afternoon! Faced such a problem. In my project, a collection of its "Person" class is attached to the ComboBox.
How can I disable some items in the collection when the RadioButton is clicked?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2017-02-25
@Zulkund

I can offer a solution that I myself, having found on the open spaces of the network, began to use and was satisfied.
1. We start a collection that will be our source

public ObservableCollection<Person>  FilteredCollection
        {
            get
            {
   return  new ObservableCollection<Person>(PersonCollection.Where(i => FilteredCheck(i)));
            }
        }

2.
public bool FilteredCheck(DemandHead item)
        {
            bool Accept=true;
// организовываем проверку как вашей душе удобно
}

// И дальше при изменении фильтра оповещаем View об изменении данных
        public bool IsFilterEnabled
        {
            get
            {
                return _IsFilterEnabled;
            }

            set
            {
                _IsFilterEnabled = value;
                base.OnPropertyChanged("IsFilterEnabled");
                base.OnPropertyChanged("FilteredCollection");

            }
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question