private static void ItemContainersGeneratedCommand_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { var ItemsControl = o as ItemsControl; if (ItemsControl == null) throw new ArgumentException("Type mismatch", "o"); var Value = (ICommand)e.NewValue; var StatusListener = GetItemContainersGeneratedCommandWeakEventListener(ItemsControl); if (Value != null) { if (StatusListener == null) StatusListener = new ItemContainerGeneratedCommandEventListener(); SetItemContainersGeneratedCommandWeakEventListener(ItemsControl, StatusListener); ItemContainerGeneratorStatusChangedEventManager.AddListener(ItemsControl, StatusListener); } else { if (StatusListener != null) { SetItemContainersGeneratedCommandWeakEventListener(ItemsControl, null); ItemContainerGeneratorStatusChangedEventManager.RemoveListener(ItemsControl, StatusListener); } } }