System.Windows.Data.DataList.UpdateFilter C# (CSharp) Method

UpdateFilter() public method

Sets the predicate to use to filter the items contained in this DataList.
public UpdateFilter ( IPredicate predicate ) : void
predicate IPredicate The predicate to use; null if no filter is to be applied.
return void
        public void UpdateFilter(IPredicate<object> predicate)
        {
            if ((_predicate == null) && (predicate == null)) {
                return;
            }

            UpdateVersion();

            if (_snapShot == null) {
                RaisePropertyChanged("Count");
                RaiseCollectionReset();
            }
            else {
                object currentItem = null;
                if (IsCurrencyEnabled) {
                    currentItem = CurrentItem;
                }

                // Potentially some items in the view are no longer in the snapshot and some new items
                // now become part of the snapshot. First we'll remove any that no longer should be in
                // the snapshot, and then we'll add whatever is.

                if (predicate != null) {
                    for (int i = _snapShot.Count - 1; i >= 0; i--) {
                        object item = _snapShot[i];
                        if (predicate.Filter(item) == false) {
                            RemoveItem(item, i, /* raisePropertyChange */ false);
                        }
                    }
                }

                if (_predicate != null) {
                    foreach (object item in _sourceData) {
                        if ((_predicate.Filter(item) == false) &&
                            ((predicate == null) || predicate.Filter(item))) {
                            AddItem(item, /* raisePropertyChange */ false);
                        }
                    }
                }

                if (currentItem != null) {
                    bool currentItemChanged = false;
                    int index = _snapShot.IndexOf(currentItem);
                    if (index == -1) {
                        index = 0;
                    }
                    CurrentIndex = index;

                    RaisePropertyChanged("CanMovePrevious");
                    RaisePropertyChanged("CanMoveNext");
                    if (currentItemChanged) {
                        RaisePropertyChanged("CurrentItem");
                    }
                }

            }

            _predicate = predicate;

            RaisePropertyChanged("Count");
        }