private static void OnItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { MyVirtualizingPanel virtualizingPanel = d as MyVirtualizingPanel; if (virtualizingPanel == null) { return; } virtualizingPanel.ClearItems(); INotifyCollectionChanged collection1 = e.OldValue as INotifyCollectionChanged; if (collection1 != null) { virtualizingPanel.UnhookCollectionChanged(collection1); } INotifyCollectionChanged collection2 = e.NewValue as INotifyCollectionChanged; if (collection2 == null) { return; } List <IVirtualizable> virtualizableList = new List <IVirtualizable>(); foreach (object obj in (IEnumerable)(collection2 as ICollection)) { if (obj is IVirtualizable) { virtualizableList.Add(obj as IVirtualizable); } } virtualizingPanel.AddItems((IEnumerable <IVirtualizable>)virtualizableList); virtualizingPanel.HookUpCollectionChanged(collection2); }
private void collection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { MyVirtualizingPanel virtualizingPanel = this; List <IVirtualizable> itemsToInsert = new List <IVirtualizable>(); if (e.NewItems != null) { foreach (object newItem in (IEnumerable)e.NewItems) { if (newItem is IVirtualizable) { itemsToInsert.Add(newItem as IVirtualizable); } } } List <IVirtualizable> virtualizableList = new List <IVirtualizable>(); if (e.OldItems != null) { foreach (object oldItem in (IEnumerable)e.OldItems) { if (oldItem is IVirtualizable) { virtualizableList.Add(oldItem as IVirtualizable); } } } if (e.Action == NotifyCollectionChangedAction.Add) { if (e.NewStartingIndex >= virtualizingPanel.VirtualizableItems.Count) { virtualizingPanel.AddItems((IEnumerable <IVirtualizable>)itemsToInsert); } else { virtualizingPanel.InsertRemoveItems(e.NewStartingIndex, itemsToInsert, virtualizingPanel.KeepScrollPositionWhenAddingItems, (IVirtualizable)null); } } else if (e.Action == NotifyCollectionChangedAction.Reset) { virtualizingPanel.ClearItems(); virtualizingPanel.AddItems((IEnumerable <IVirtualizable>)virtualizingPanel.ItemsSource); } else { if (e.Action != NotifyCollectionChangedAction.Remove || virtualizableList.Count <= 0) { return; } virtualizingPanel.RemoveItem(virtualizableList[0]); } }
private static void OnItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { MyVirtualizingPanel virtualizingPanel = d as MyVirtualizingPanel; if (virtualizingPanel == null) { return; } virtualizingPanel.ClearItems(); // ISSUE: explicit reference operation INotifyCollectionChanged oldValue = e.OldValue as INotifyCollectionChanged; if (oldValue != null) { virtualizingPanel.UnhookCollectionChanged(oldValue); } // ISSUE: explicit reference operation INotifyCollectionChanged newValue = e.NewValue as INotifyCollectionChanged; if (newValue == null) { return; } List <IVirtualizable> virtualizableList = new List <IVirtualizable>(); IEnumerator enumerator = (newValue as ICollection).GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.Current; if (current is IVirtualizable) { virtualizableList.Add(current as IVirtualizable); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } virtualizingPanel.AddItems((IEnumerable <IVirtualizable>)virtualizableList); virtualizingPanel.HookUpCollectionChanged(newValue); }
private void collection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { MyVirtualizingPanel virtualizingPanel = this; List <IVirtualizable> itemsToInsert = new List <IVirtualizable>(); if (e.NewItems != null) { IEnumerator enumerator = e.NewItems.GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.Current; if (current is IVirtualizable) { itemsToInsert.Add(current as IVirtualizable); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } List <IVirtualizable> virtualizableList = new List <IVirtualizable>(); if (e.OldItems != null) { IEnumerator enumerator = e.OldItems.GetEnumerator(); try { while (enumerator.MoveNext()) { object current = enumerator.Current; if (current is IVirtualizable) { virtualizableList.Add(current as IVirtualizable); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } if (e.Action == NotifyCollectionChangedAction.Add) { if (e.NewStartingIndex >= virtualizingPanel.VirtualizableItems.Count) { virtualizingPanel.AddItems((IEnumerable <IVirtualizable>)itemsToInsert); } else { virtualizingPanel.InsertRemoveItems(e.NewStartingIndex, itemsToInsert, virtualizingPanel.KeepScrollPositionWhenAddingItems, null); } } else if (e.Action == NotifyCollectionChangedAction.Reset) { virtualizingPanel.ClearItems(); virtualizingPanel.AddItems((IEnumerable <IVirtualizable>)virtualizingPanel.ItemsSource); } else { if (e.Action != NotifyCollectionChangedAction.Remove || virtualizableList.Count <= 0) { return; } virtualizingPanel.RemoveItem(virtualizableList[0]); } }