private static void OnEnableIndexingChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e) { if (e.NewValue != null && e.NewValue is INotifyCollectionChanged) { ItemsControl control = depObj as ItemsControl; if (control != null) { ((INotifyCollectionChanged)e.NewValue).CollectionChanged += (sender, args) => { var list = e.NewValue as IList; if (args.Action == NotifyCollectionChangedAction.Move) { IndexManager.Move(list, args.OldStartingIndex, args.NewStartingIndex); } else if (args.Action == NotifyCollectionChangedAction.Add) { IndexManager.Add(list); } else if (args.Action == NotifyCollectionChangedAction.Remove) { IndexManager.Remove(list, args.OldStartingIndex); } }; } } }