Solution: how to skip points

Jun 26, 2009 at 6:20 PM

I had a need to skip some of the points in the source ObservableCollection. This was simple to do:

1. Add a new constructor to EnumerablePointEnumerator:

        public EnumerablePointEnumerator(EnumerableDataSource<T> dataSource, IEnumerator ienum)
        {
            this.dataSource = dataSource;
            enumerator = ienum;
        }
2. Derive a new class from EnumerableDataSource<T> and override GetEnumerator(). In here you can use LINQ generate an enumerator that does what you need. E.g.
        /// <summary>
        /// Gets the point enumerator. Will skip x,y values that are not up to date.
        /// </summary>
        public override IPointEnumerator GetEnumerator(DependencyObject context)
        {
            return new EnumerablePointEnumerator<T>(this, _Collection.Where(IsValidDataPoint).GetEnumerator());
        }
In my implementation, _Collection is the source ObservableCollection and IsValidDataPoint is a class method that returns false is the collection element isn't valid.

Editor
Jul 6, 2009 at 1:09 PM

Hi,

 

Maybe it is possible to skip points before passing them to ctor of EnumerableDataSource? For example, the code could be the following:

 

var collection = new ObservableCollection<Point>();
var filteredCollection = collection.Where(IsValidDataPoint);
var dataSource = new EnumerableDataSource<Point>(filteredCollection);


Best regards,
Mikhail.