public override void OnAttached() { if (AssociatedObject is IDragSource dragSource) { DragSource = dragSource; DragSource.ItemsChanged += () => { foreach (FrameworkElement item in DragSource.GetItems()) { item.PreviewMouseLeftButtonDown -= Item_OnPreviewMouseLeftButtonDown; item.PreviewMouseMove -= Item_OnPreviewMouseMove; item.PreviewMouseLeftButtonDown += Item_OnPreviewMouseLeftButtonDown; item.PreviewMouseMove += Item_OnPreviewMouseMove; } }; Background.PreviewMouseMove += Background_OnPreviewMouseMove; Background.MouseLeftButtonUp += Background_OnMouseLeftButtonUp; } else { throw new ArgumentException("This behavior could be attached only to objects of type IDragSource"); } }