예제 #1
0
파일: XYSeries.cs 프로젝트: sulerzh/chart
        internal void LoadDataFromVirtualizer(IEnumerable data)
        {
            object firstNewDataObject = (object)null;
            int    num = -1;

            if (!EnumerableFunctions.IsEmpty(data))
            {
                firstNewDataObject = EnumerableFunctions.FastElementAt <object>(data, 0);
                if (firstNewDataObject != null)
                {
                    num = EnumerableFunctions.FindIndexOf <DataPoint>((IEnumerable <DataPoint>) this.DataPoints, (Func <DataPoint, bool>)(item =>
                    {
                        if (item != firstNewDataObject)
                        {
                            return(item.DataContext == firstNewDataObject);
                        }
                        return(true);
                    }));
                }
            }
            if (num < 0)
            {
                this.ItemsSource = data;
            }
            else
            {
                for (; num > 0; --num)
                {
                    this.DataPoints.RemoveAt(0);
                }
                int index = 0;
                foreach (object obj in data)
                {
                    if (index >= 0 && index < this.DataPoints.Count && (this.DataPoints[index] == obj || this.DataPoints[index].DataContext == obj))
                    {
                        ++index;
                    }
                    else
                    {
                        if (index >= 0)
                        {
                            while (index < this.DataPoints.Count)
                            {
                                this.DataPoints.RemoveAt(index);
                            }
                            index = -1;
                        }
                        DataPoint dataPoint = obj as DataPoint;
                        if (dataPoint == null || !this.IsDataPointCompatible(dataPoint))
                        {
                            dataPoint             = this.CreateDataPoint();
                            dataPoint.DataContext = obj;
                            if (this.ItemsBinder != null)
                            {
                                this.ItemsBinder.Bind(dataPoint, dataPoint.DataContext);
                            }
                        }
                        this.DataPoints.Add(dataPoint);
                    }
                }
            }
        }