private void UpdatePage(int page, IList results, uint stateWhenRequested, bool previousNextRequest)
        {
            if (stateWhenRequested != State)
            {
                // this request may contain out-of-date data, so ignore it
                return;
            }

            bool stillRelevant = _requestedPages.Remove(page);

            if (!stillRelevant)
            {
                return;
            }

            _fetchedPages.Add(page);

            var startIndex = page * _pageSize;

            // guard against rogue collection sources returning too many results
            var count = Math.Min(results.Count, _pageSize);

            for (int i = 0; i < count; i++)
            {
                var index       = startIndex + i;
                var virtualItem = VirtualItems[index] ?? (VirtualItems[index] = new VirtualItem <object>(this, index));
                if (virtualItem.Item == null || results[i] == null || !_equalityComparer.Equals(virtualItem.Item, results[i]))
                {
                    virtualItem.SupplyValue(results[i]);
                }

                if (!previousNextRequest || virtualItem.IsAskedByIndex)
                {
#if SILVERLIGHT
                    if (firstTimeIndexZero && i == 0)
                    {
                        firstTimeIndexZero = false;
                        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                    }
                    else
                    {
                        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove,
                                                                                 VirtualItems[startIndex + i].Item, startIndex + i));
                        OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add,
                                                                                 results[i], startIndex + i));
                    }
#else
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove,
                                                                             VirtualItems[startIndex + i].Item, startIndex + i));
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add,
                                                                             results[i], startIndex + i));
#endif
                }
            }

            if (count > 0)
            {
                OnItemsRealized(new ItemsRealizedEventArgs(startIndex, count));
            }
        }
        private object getbyIndex(int index, bool byIlist)
        {
            if (index >= Count)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (byIlist)
            {
                RealizeItemRequested(index, true);
            }

            if (!byIlist)
            {
                return(null);
            }

            var itm = VirtualItems[index] ?? (VirtualItems[index] = new VirtualItem <object>(this, index));

            itm.IsAskedByIndex = byIlist;

            return(itm.Item);
        }