private static void AttachChanged(object dependencyObject, DependencyPropertyChangedEventArgs e) { dependencyObject.DbC_Assure(value => value is FrameworkElement || value is FrameworkContentElement, "Attach can only be used on Framework(Content)Element"); if (e.OldValue is INotifyPropertyChanged) { INotifyPropertyChanged EventSource = (INotifyPropertyChanged)e.OldValue; EventConnector.GetEventConnector(EventSource).RemoveTarget((DependencyObject)dependencyObject); } if (e.NewValue is INotifyPropertyChanged) { INotifyPropertyChanged EventSource = (INotifyPropertyChanged)e.NewValue; EventConnector.GetEventConnector(EventSource).AddTarget((DependencyObject)dependencyObject); } }