private void PopulateItems(IEnumerable oldSource, IEnumerable newSource) { if (oldSource != null) { ItemMap.Clear(); ItemMap = null; if (oldSource is INotifyCollectionChanged) { var incc = oldSource as INotifyCollectionChanged; incc.CollectionChanged -= OnItemsCollectionChanged; } } if (newSource != null) { if (newSource is INotifyCollectionChanged) { var incc = newSource as INotifyCollectionChanged; incc.CollectionChanged += OnItemsCollectionChanged; } ItemMap = new Dictionary <object, ViewItem>(); foreach (var modelItem in newSource) { PrepareContainer(modelItem); } } }