using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace GongSolutions.Wpf.DragDrop { public static partial class DragDrop { /// /// The default data format which will be used for the drag and drop actions. /// public static DataFormat DataFormat { get; } = DataFormats.GetDataFormat("GongSolutions.Wpf.DragDrop"); /// /// Gets or sets the data format which will be used for the drag and drop actions. /// public static readonly DependencyProperty DataFormatProperty = DependencyProperty.RegisterAttached(nameof(DataFormat), typeof(DataFormat), typeof(DragDrop), new PropertyMetadata(DragDrop.DataFormat)); /// /// Gets the data format which will be used for the drag and drop actions. /// public static DataFormat GetDataFormat(UIElement source) { return (DataFormat)source.GetValue(DataFormatProperty); } /// /// Sets the data format which will be used for the drag and drop actions. /// public static void SetDataFormat(UIElement source, DataFormat value) { source.SetValue(DataFormatProperty, value); } /// /// Gets or Sets whether the control can be used as drag source. /// public static readonly DependencyProperty IsDragSourceProperty = DependencyProperty.RegisterAttached("IsDragSource", typeof(bool), typeof(DragDrop), new UIPropertyMetadata(false, OnIsDragSourceChanged)); /// /// Gets whether the control can be used as drag source. /// public static bool GetIsDragSource(UIElement target) { return (bool)target.GetValue(IsDragSourceProperty); } /// /// Sets whether the control can be used as drag source. /// public static void SetIsDragSource(UIElement target, bool value) { target.SetValue(IsDragSourceProperty, value); } private static void OnIsDragSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var uiElement = (UIElement)d; if ((bool)e.NewValue) { uiElement.PreviewMouseLeftButtonDown += DragSourceOnMouseLeftButtonDown; uiElement.PreviewMouseLeftButtonUp += DragSourceOnMouseLeftButtonUp; uiElement.PreviewMouseMove += DragSourceOnMouseMove; uiElement.QueryContinueDrag += DragSourceOnQueryContinueDrag; } else { uiElement.PreviewMouseLeftButtonDown -= DragSourceOnMouseLeftButtonDown; uiElement.PreviewMouseLeftButtonUp -= DragSourceOnMouseLeftButtonUp; uiElement.PreviewMouseMove -= DragSourceOnMouseMove; uiElement.QueryContinueDrag -= DragSourceOnQueryContinueDrag; } } /// /// Gets or Sets whether the control can be used as drop target. /// public static readonly DependencyProperty IsDropTargetProperty = DependencyProperty.RegisterAttached("IsDropTarget", typeof(bool), typeof(DragDrop), new UIPropertyMetadata(false, OnIsDropTargetChanged)); /// /// Gets whether the control can be used as drop target. /// public static bool GetIsDropTarget(UIElement target) { return (bool)target.GetValue(IsDropTargetProperty); } /// /// Sets whether the control can be used as drop target. /// public static void SetIsDropTarget(UIElement target, bool value) { target.SetValue(IsDropTargetProperty, value); } private static void OnIsDropTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var uiElement = (UIElement)d; if ((bool)e.NewValue) { uiElement.SetCurrentValue(UIElement.AllowDropProperty, true); RegisterDragDropEvents(uiElement, GetDropEventType(d)); } else { uiElement.SetCurrentValue(UIElement.AllowDropProperty, false); UnregisterDragDropEvents(uiElement, GetDropEventType(d)); Mouse.OverrideCursor = null; } } /// /// Gets which type of events are subscribed for the drag and drop events. /// public static EventType GetDropEventType(DependencyObject obj) { return (EventType)obj.GetValue(DropEventTypeProperty); } /// /// Sets which type of events are subscribed for the drag and drop events. /// public static void SetDropEventType(DependencyObject obj, EventType value) { obj.SetValue(DropEventTypeProperty, value); } /// /// Gets or sets the events which are subscribed for the drag and drop events /// public static readonly DependencyProperty DropEventTypeProperty = DependencyProperty.RegisterAttached("DropEventType", typeof(EventType), typeof(DragDrop), new PropertyMetadata(EventType.Auto, OnDropEventTypeChanged)); private static void OnDropEventTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var uiElement = (UIElement)d; if (!GetIsDropTarget(uiElement)) return; UnregisterDragDropEvents(uiElement, (EventType)e.OldValue); RegisterDragDropEvents(uiElement, (EventType)e.NewValue); } private static void RegisterDragDropEvents(UIElement uiElement, EventType eventType) { switch (eventType) { case EventType.Auto: if (uiElement is ItemsControl) { // use normal events for ItemsControls uiElement.DragEnter += DropTargetOnDragEnter; uiElement.DragLeave += DropTargetOnDragLeave; uiElement.DragOver += DropTargetOnDragOver; uiElement.Drop += DropTargetOnDrop; uiElement.GiveFeedback += DropTargetOnGiveFeedback; } else { // issue #85: try using preview events for all other elements than ItemsControls uiElement.PreviewDragEnter += DropTargetOnPreviewDragEnter; uiElement.PreviewDragLeave += DropTargetOnDragLeave; uiElement.PreviewDragOver += DropTargetOnPreviewDragOver; uiElement.PreviewDrop += DropTargetOnPreviewDrop; uiElement.PreviewGiveFeedback += DropTargetOnGiveFeedback; } break; case EventType.Tunneled: uiElement.PreviewDragEnter += DropTargetOnPreviewDragEnter; uiElement.PreviewDragLeave += DropTargetOnDragLeave; uiElement.PreviewDragOver += DropTargetOnPreviewDragOver; uiElement.PreviewDrop += DropTargetOnPreviewDrop; uiElement.PreviewGiveFeedback += DropTargetOnGiveFeedback; break; case EventType.Bubbled: uiElement.DragEnter += DropTargetOnDragEnter; uiElement.DragLeave += DropTargetOnDragLeave; uiElement.DragOver += DropTargetOnDragOver; uiElement.Drop += DropTargetOnDrop; uiElement.GiveFeedback += DropTargetOnGiveFeedback; break; case EventType.TunneledBubbled: uiElement.PreviewDragEnter += DropTargetOnPreviewDragEnter; uiElement.PreviewDragLeave += DropTargetOnDragLeave; uiElement.PreviewDragOver += DropTargetOnPreviewDragOver; uiElement.PreviewDrop += DropTargetOnPreviewDrop; uiElement.PreviewGiveFeedback += DropTargetOnGiveFeedback; uiElement.DragEnter += DropTargetOnDragEnter; uiElement.DragLeave += DropTargetOnDragLeave; uiElement.DragOver += DropTargetOnDragOver; uiElement.Drop += DropTargetOnDrop; uiElement.GiveFeedback += DropTargetOnGiveFeedback; break; default: throw new ArgumentException("Unknown value for eventType: " + eventType.ToString(), nameof(eventType)); } } private static void UnregisterDragDropEvents(UIElement uiElement, EventType eventType) { switch (eventType) { case EventType.Auto: if (uiElement is ItemsControl) { // use normal events for ItemsControls uiElement.DragEnter -= DropTargetOnDragEnter; uiElement.DragLeave -= DropTargetOnDragLeave; uiElement.DragOver -= DropTargetOnDragOver; uiElement.Drop -= DropTargetOnDrop; uiElement.GiveFeedback -= DropTargetOnGiveFeedback; } else { // issue #85: try using preview events for all other elements than ItemsControls uiElement.PreviewDragEnter -= DropTargetOnPreviewDragEnter; uiElement.PreviewDragLeave -= DropTargetOnDragLeave; uiElement.PreviewDragOver -= DropTargetOnPreviewDragOver; uiElement.PreviewDrop -= DropTargetOnPreviewDrop; uiElement.PreviewGiveFeedback -= DropTargetOnGiveFeedback; } break; case EventType.Tunneled: uiElement.PreviewDragEnter -= DropTargetOnPreviewDragEnter; uiElement.PreviewDragLeave -= DropTargetOnDragLeave; uiElement.PreviewDragOver -= DropTargetOnPreviewDragOver; uiElement.PreviewDrop -= DropTargetOnPreviewDrop; uiElement.PreviewGiveFeedback -= DropTargetOnGiveFeedback; break; case EventType.Bubbled: uiElement.DragEnter -= DropTargetOnDragEnter; uiElement.DragLeave -= DropTargetOnDragLeave; uiElement.DragOver -= DropTargetOnDragOver; uiElement.Drop -= DropTargetOnDrop; uiElement.GiveFeedback -= DropTargetOnGiveFeedback; break; case EventType.TunneledBubbled: uiElement.PreviewDragEnter -= DropTargetOnPreviewDragEnter; uiElement.PreviewDragLeave -= DropTargetOnDragLeave; uiElement.PreviewDragOver -= DropTargetOnPreviewDragOver; uiElement.PreviewDrop -= DropTargetOnPreviewDrop; uiElement.PreviewGiveFeedback -= DropTargetOnGiveFeedback; uiElement.DragEnter -= DropTargetOnDragEnter; uiElement.DragLeave -= DropTargetOnDragLeave; uiElement.DragOver -= DropTargetOnDragOver; uiElement.Drop -= DropTargetOnDrop; uiElement.GiveFeedback -= DropTargetOnGiveFeedback; break; default: throw new ArgumentException("Unknown value for eventType: " + eventType.ToString(), nameof(eventType)); } } /// /// Gets or Sets whether the control can be used as drag source together with the right mouse. /// public static readonly DependencyProperty CanDragWithMouseRightButtonProperty = DependencyProperty.RegisterAttached("CanDragWithMouseRightButton", typeof(bool), typeof(DragDrop), new UIPropertyMetadata(false, OnCanDragWithMouseRightButtonChanged)); /// /// Gets whether the control can be used as drag source together with the right mouse. /// public static bool GetCanDragWithMouseRightButton(UIElement target) { return (bool)target.GetValue(CanDragWithMouseRightButtonProperty); } /// /// Sets whether the control can be used as drag source together with the right mouse. /// public static void SetCanDragWithMouseRightButton(UIElement target, bool value) { target.SetValue(CanDragWithMouseRightButtonProperty, value); } private static void OnCanDragWithMouseRightButtonChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var uiElement = (UIElement)d; if ((bool)e.NewValue) { uiElement.PreviewMouseRightButtonDown += DragSourceOnMouseRightButtonDown; uiElement.PreviewMouseRightButtonUp += DragSourceOnMouseRightButtonUp; } else { uiElement.PreviewMouseRightButtonDown -= DragSourceOnMouseRightButtonDown; uiElement.PreviewMouseRightButtonUp -= DragSourceOnMouseRightButtonUp; } } /// /// Gets the default DragHandler. /// public static IDragSource DefaultDragHandler { get; } = new DefaultDragHandler(); /// /// Gets the default DropHandler. /// public static IDropTarget DefaultDropHandler { get; } = new DefaultDropHandler(); /// /// Gets or Sets the handler for the drag action. /// public static readonly DependencyProperty DragHandlerProperty = DependencyProperty.RegisterAttached("DragHandler", typeof(IDragSource), typeof(DragDrop)); /// /// Gets the handler for the drag action. /// public static IDragSource GetDragHandler(UIElement target) { return (IDragSource)target.GetValue(DragHandlerProperty); } /// /// Sets the handler for the drag action. /// public static void SetDragHandler(UIElement target, IDragSource value) { target.SetValue(DragHandlerProperty, value); } /// /// Gets or Sets the handler for the drop action. /// public static readonly DependencyProperty DropHandlerProperty = DependencyProperty.RegisterAttached("DropHandler", typeof(IDropTarget), typeof(DragDrop)); /// /// Gets the handler for the drop action. /// public static IDropTarget GetDropHandler(UIElement target) { return (IDropTarget)target.GetValue(DropHandlerProperty); } /// /// Sets the handler for the drop action. /// public static void SetDropHandler(UIElement target, IDropTarget value) { target.SetValue(DropHandlerProperty, value); } /// /// Gets or Sets the ScrollingMode for the drop action. /// public static readonly DependencyProperty DropScrollingModeProperty = DependencyProperty.RegisterAttached("DropScrollingMode", typeof(ScrollingMode), typeof(DragDrop), new PropertyMetadata(ScrollingMode.Both)); /// /// Gets the ScrollingMode for the drop action. /// public static ScrollingMode GetDropScrollingMode(UIElement target) { return (ScrollingMode)target.GetValue(DropScrollingModeProperty); } /// /// Sets the ScrollingMode for the drop action. /// public static void SetDropScrollingMode(UIElement target, ScrollingMode value) { target.SetValue(DropScrollingModeProperty, value); } /// /// Gets or Sets whether to show the DropTargetAdorner (DropTargetInsertionAdorner) on an empty target too. /// public static readonly DependencyProperty ShowAlwaysDropTargetAdornerProperty = DependencyProperty.RegisterAttached("ShowAlwaysDropTargetAdorner", typeof(bool), typeof(DragDrop), new PropertyMetadata(false)); /// /// Gets whether to show the DropTargetAdorner (DropTargetInsertionAdorner) on an empty target too. /// public static bool GetShowAlwaysDropTargetAdorner(UIElement target) { return (bool)target.GetValue(ShowAlwaysDropTargetAdornerProperty); } /// /// Sets whether to show the DropTargetAdorner (DropTargetInsertionAdorner) on an empty target too. /// public static void SetShowAlwaysDropTargetAdorner(UIElement target, bool value) { target.SetValue(ShowAlwaysDropTargetAdornerProperty, value); } /// /// Gets or Sets the brush for the DropTargetAdorner. /// public static readonly DependencyProperty DropTargetAdornerBrushProperty = DependencyProperty.RegisterAttached("DropTargetAdornerBrush", typeof(Brush), typeof(DragDrop), new PropertyMetadata((Brush)null)); /// /// Gets the brush for the DropTargetAdorner. /// public static Brush GetDropTargetAdornerBrush(UIElement target) { return (Brush)target.GetValue(DropTargetAdornerBrushProperty); } /// /// Sets the brush for the DropTargetAdorner. /// public static void SetDropTargetAdornerBrush(UIElement target, Brush value) { target.SetValue(DropTargetAdornerBrushProperty, value); } /// /// Gets or Sets a context for a control. Only controls with the same context are allowed for drag or drop actions. /// public static readonly DependencyProperty DragDropContextProperty = DependencyProperty.RegisterAttached("DragDropContext", typeof(string), typeof(DragDrop), new UIPropertyMetadata(string.Empty)); /// /// Gets a context for a control. Only controls with the same context are allowed for drag or drop actions. /// public static string GetDragDropContext(UIElement target) { return (string)target.GetValue(DragDropContextProperty); } /// /// Sets a context for a control. Only controls with the same context are allowed for drag or drop actions. /// public static void SetDragDropContext(UIElement target, string value) { target.SetValue(DragDropContextProperty, value); } /// /// Gets or Sets whether an element under the mouse should be ignored for the drag action. /// public static readonly DependencyProperty DragSourceIgnoreProperty = DependencyProperty.RegisterAttached("DragSourceIgnore", typeof(bool), typeof(DragDrop), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits)); /// /// Gets whether an element under the mouse should be ignored for the drag action. /// public static bool GetDragSourceIgnore(UIElement source) { return (bool)source.GetValue(DragSourceIgnoreProperty); } /// /// Sets whether an element under the mouse should be ignored for the drag action. /// public static void SetDragSourceIgnore(UIElement source, bool value) { source.SetValue(DragSourceIgnoreProperty, value); } /// /// Gets or Sets wheter the drag action should be started only directly on a selected item /// or also on the free control space (e.g. in a ListBox). /// public static readonly DependencyProperty DragDirectlySelectedOnlyProperty = DependencyProperty.RegisterAttached("DragDirectlySelectedOnly", typeof(bool), typeof(DragDrop), new PropertyMetadata(false)); /// /// Gets wheter the drag action should be started only directly on a selected item. /// public static bool GetDragDirectlySelectedOnly(DependencyObject obj) { return (bool)obj.GetValue(DragDirectlySelectedOnlyProperty); } /// /// Sets wheter the drag action should be started only directly on a selected item. /// public static void SetDragDirectlySelectedOnly(DependencyObject obj, bool value) { obj.SetValue(DragDirectlySelectedOnlyProperty, value); } /// /// The drag drop copy key state property (default None). /// So the drag drop action is /// - Move, within the same control or from one to another, if the drag drop key state is None /// - Copy, from one to another control with the given drag drop copy key state /// public static readonly DependencyProperty DragDropCopyKeyStateProperty = DependencyProperty.RegisterAttached("DragDropCopyKeyState", typeof(DragDropKeyStates), typeof(DragDrop), new PropertyMetadata(default(DragDropKeyStates))); /// /// Gets the copy key state which indicates the effect of the drag drop operation. /// public static DragDropKeyStates GetDragDropCopyKeyState(UIElement target) { return (DragDropKeyStates)target.GetValue(DragDropCopyKeyStateProperty); } /// /// Sets the copy key state which indicates the effect of the drag drop operation. /// public static void SetDragDropCopyKeyState(UIElement target, DragDropKeyStates value) { target.SetValue(DragDropCopyKeyStateProperty, value); } /// /// Gets or Sets whether if the default DragAdorner should be use. /// public static readonly DependencyProperty UseDefaultDragAdornerProperty = DependencyProperty.RegisterAttached("UseDefaultDragAdorner", typeof(bool), typeof(DragDrop), new PropertyMetadata(false)); /// /// Gets whether if the default DragAdorner is used. /// public static bool GetUseDefaultDragAdorner(UIElement target) { return (bool)target.GetValue(UseDefaultDragAdornerProperty); } /// /// Sets whether if the default DragAdorner should be use. /// public static void SetUseDefaultDragAdorner(UIElement target, bool value) { target.SetValue(UseDefaultDragAdornerProperty, value); } /// /// Gets or Sets the opacity of the default DragAdorner. /// public static readonly DependencyProperty DefaultDragAdornerOpacityProperty = DependencyProperty.RegisterAttached("DefaultDragAdornerOpacity", typeof(double), typeof(DragDrop), new PropertyMetadata(0.8)); /// /// Gets the opacity of the default DragAdorner. /// public static double GetDefaultDragAdornerOpacity(UIElement target) { return (double)target.GetValue(DefaultDragAdornerOpacityProperty); } /// /// Sets the opacity of the default DragAdorner. /// public static void SetDefaultDragAdornerOpacity(UIElement target, double value) { target.SetValue(DefaultDragAdornerOpacityProperty, value); } /// /// Gets or Sets the horizontal and vertical proportion at which the pointer will anchor on the DragAdorner. /// public static readonly DependencyProperty DragMouseAnchorPointProperty = DependencyProperty.RegisterAttached("DragMouseAnchorPoint", typeof(Point), typeof(DragDrop), new PropertyMetadata(new Point(0, 1))); /// /// Gets the horizontal and vertical proportion at which the pointer will anchor on the DragAdorner. /// public static Point GetDragMouseAnchorPoint(UIElement target) { return (Point)target.GetValue(DragMouseAnchorPointProperty); } /// /// Sets the horizontal and vertical proportion at which the pointer will anchor on the DragAdorner. /// public static void SetDragMouseAnchorPoint(UIElement target, Point value) { target.SetValue(DragMouseAnchorPointProperty, value); } /// /// Gets or Sets the translation transform which will be used for the DragAdorner. /// public static readonly DependencyProperty DragAdornerTranslationProperty = DependencyProperty.RegisterAttached("DragAdornerTranslation", typeof(Point), typeof(DragDrop), new PropertyMetadata(new Point(-4, -4))); /// /// Gets the translation transform which will be used for the DragAdorner. /// public static Point GetDragAdornerTranslation(UIElement element) { return (Point)element.GetValue(DragAdornerTranslationProperty); } /// /// Sets the translation transform which will be used for the DragAdorner. /// public static void SetDragAdornerTranslation(UIElement element, Point value) { element.SetValue(DragAdornerTranslationProperty, value); } /// /// Gets or Sets the translation transform which will be used for the EffectAdorner. /// public static readonly DependencyProperty EffectAdornerTranslationProperty = DependencyProperty.RegisterAttached("EffectAdornerTranslation", typeof(Point), typeof(DragDrop), new PropertyMetadata(new Point(16, 16))); /// /// Gets the translation transform which will be used for the EffectAdorner. /// public static Point GetEffectAdornerTranslation(UIElement element) { return (Point)element.GetValue(EffectAdornerTranslationProperty); } /// /// Sets the translation transform which will be used for the EffectAdorner. /// public static void SetEffectAdornerTranslation(UIElement element, Point value) { element.SetValue(EffectAdornerTranslationProperty, value); } /// /// Gets or Sets a DataTemplate for the DragAdorner. /// public static readonly DependencyProperty DragAdornerTemplateProperty = DependencyProperty.RegisterAttached("DragAdornerTemplate", typeof(DataTemplate), typeof(DragDrop)); /// /// Gets the DataTemplate for the DragAdorner. /// public static DataTemplate GetDragAdornerTemplate(UIElement target) { return (DataTemplate)target.GetValue(DragAdornerTemplateProperty); } /// /// Sets the DataTemplate for the DragAdorner. /// public static void SetDragAdornerTemplate(UIElement target, DataTemplate value) { target.SetValue(DragAdornerTemplateProperty, value); } /// /// Gets or Sets a DataTemplate for the DragAdorner based on the DropTarget. /// public static readonly DependencyProperty DropAdornerTemplateProperty = DependencyProperty.RegisterAttached("DropAdornerTemplate", typeof(DataTemplate), typeof(DragDrop)); /// /// Gets the DataTemplate for the DragAdorner based on the DropTarget. /// public static DataTemplate GetDropAdornerTemplate(UIElement target) { return (DataTemplate)target.GetValue(DropAdornerTemplateProperty); } /// /// Sets the DataTemplate for the DragAdorner based on the DropTarget. /// public static void SetDropAdornerTemplate(UIElement target, DataTemplate value) { target.SetValue(DropAdornerTemplateProperty, value); } /// /// Gets or Sets a DataTemplateSelector for the DragAdorner. /// public static readonly DependencyProperty DragAdornerTemplateSelectorProperty = DependencyProperty.RegisterAttached("DragAdornerTemplateSelector", typeof(DataTemplateSelector), typeof(DragDrop), new PropertyMetadata(default(DataTemplateSelector))); /// /// Gets the DataTemplateSelector for the DragAdorner. /// public static void SetDragAdornerTemplateSelector(DependencyObject element, DataTemplateSelector value) { element.SetValue(DragAdornerTemplateSelectorProperty, value); } /// /// Gets the DataTemplateSelector for the DragAdorner. /// public static DataTemplateSelector GetDragAdornerTemplateSelector(DependencyObject element) { return (DataTemplateSelector)element.GetValue(DragAdornerTemplateSelectorProperty); } /// /// Gets or Sets a DataTemplateSelector for the DragAdorner based on the DropTarget. /// public static readonly DependencyProperty DropAdornerTemplateSelectorProperty = DependencyProperty.RegisterAttached("DropAdornerTemplateSelector", typeof(DataTemplateSelector), typeof(DragDrop), new PropertyMetadata(default(DataTemplateSelector))); /// /// Gets the DataTemplateSelector for the DragAdorner based on the DropTarget. /// public static void SetDropAdornerTemplateSelector(DependencyObject element, DataTemplateSelector value) { element.SetValue(DropAdornerTemplateSelectorProperty, value); } /// /// Gets the DataTemplateSelector for the DragAdorner based on the DropTarget. /// public static DataTemplateSelector GetDropAdornerTemplateSelector(DependencyObject element) { return (DataTemplateSelector)element.GetValue(DropAdornerTemplateSelectorProperty); } /// /// Use descendant bounds of the VisualSourceItem as MinWidth for the DragAdorner. /// public static readonly DependencyProperty UseVisualSourceItemSizeForDragAdornerProperty = DependencyProperty.RegisterAttached("UseVisualSourceItemSizeForDragAdorner", typeof(bool), typeof(DragDrop), new PropertyMetadata(false)); /// /// Get the flag which indicates if the DragAdorner use the descendant bounds of the VisualSourceItem as MinWidth. /// public static bool GetUseVisualSourceItemSizeForDragAdorner(UIElement target) { return (bool)target.GetValue(UseVisualSourceItemSizeForDragAdornerProperty); } /// /// Set the flag which indicates if the DragAdorner use the descendant bounds of the VisualSourceItem as MinWidth. /// public static void SetUseVisualSourceItemSizeForDragAdorner(UIElement target, bool value) { target.SetValue(UseVisualSourceItemSizeForDragAdornerProperty, value); } /// /// Gets or Sets whether if the default DataTemplate for the effects should be use. /// public static readonly DependencyProperty UseDefaultEffectDataTemplateProperty = DependencyProperty.RegisterAttached("UseDefaultEffectDataTemplate", typeof(bool), typeof(DragDrop), new PropertyMetadata(false)); /// /// Gets whether if the default DataTemplate for the effects should be use. /// public static bool GetUseDefaultEffectDataTemplate(UIElement target) { return (bool)target.GetValue(UseDefaultEffectDataTemplateProperty); } /// /// Sets whether if the default DataTemplate for the effects should be use. /// public static void SetUseDefaultEffectDataTemplate(UIElement target, bool value) { target.SetValue(UseDefaultEffectDataTemplateProperty, value); } /// /// Gets or Sets a EffectAdorner DataTemplate for effect type None. /// public static readonly DependencyProperty EffectNoneAdornerTemplateProperty = DependencyProperty.RegisterAttached("EffectNoneAdornerTemplate", typeof(DataTemplate), typeof(DragDrop), new PropertyMetadata((DataTemplate)null)); /// /// Gets a EffectAdorner DataTemplate for effect type None. /// public static DataTemplate GetEffectNoneAdornerTemplate(UIElement target) { return (DataTemplate)target.GetValue(EffectNoneAdornerTemplateProperty); } /// /// Sets a EffectAdorner DataTemplate for effect type None. /// public static void SetEffectNoneAdornerTemplate(UIElement target, DataTemplate value) { target.SetValue(EffectNoneAdornerTemplateProperty, value); } /// /// Gets or Sets a EffectAdorner DataTemplate for effect type Copy. /// public static readonly DependencyProperty EffectCopyAdornerTemplateProperty = DependencyProperty.RegisterAttached("EffectCopyAdornerTemplate", typeof(DataTemplate), typeof(DragDrop), new PropertyMetadata((DataTemplate)null)); /// /// Gets a EffectAdorner DataTemplate for effect type Copy. /// public static DataTemplate GetEffectCopyAdornerTemplate(UIElement target) { return (DataTemplate)target.GetValue(EffectCopyAdornerTemplateProperty); } /// /// Sets a EffectAdorner DataTemplate for effect type Copy. /// public static void SetEffectCopyAdornerTemplate(UIElement target, DataTemplate value) { target.SetValue(EffectCopyAdornerTemplateProperty, value); } /// /// Gets or Sets a EffectAdorner DataTemplate for effect type Move. /// public static readonly DependencyProperty EffectMoveAdornerTemplateProperty = DependencyProperty.RegisterAttached("EffectMoveAdornerTemplate", typeof(DataTemplate), typeof(DragDrop), new PropertyMetadata((DataTemplate)null)); /// /// Gets a EffectAdorner DataTemplate for effect type Move. /// public static DataTemplate GetEffectMoveAdornerTemplate(UIElement target) { return (DataTemplate)target.GetValue(EffectMoveAdornerTemplateProperty); } /// /// Sets a EffectAdorner DataTemplate for effect type Move. /// public static void SetEffectMoveAdornerTemplate(UIElement target, DataTemplate value) { target.SetValue(EffectMoveAdornerTemplateProperty, value); } /// /// Gets or Sets a EffectAdorner DataTemplate for effect type Link. /// public static readonly DependencyProperty EffectLinkAdornerTemplateProperty = DependencyProperty.RegisterAttached("EffectLinkAdornerTemplate", typeof(DataTemplate), typeof(DragDrop), new PropertyMetadata((DataTemplate)null)); /// /// Gets a EffectAdorner DataTemplate for effect type Link. /// public static DataTemplate GetEffectLinkAdornerTemplate(UIElement target) { return (DataTemplate)target.GetValue(EffectLinkAdornerTemplateProperty); } /// /// Sets a EffectAdorner DataTemplate for effect type Link. /// public static void SetEffectLinkAdornerTemplate(UIElement target, DataTemplate value) { target.SetValue(EffectLinkAdornerTemplateProperty, value); } /// /// Gets or Sets a EffectAdorner DataTemplate for effect type All. /// public static readonly DependencyProperty EffectAllAdornerTemplateProperty = DependencyProperty.RegisterAttached("EffectAllAdornerTemplate", typeof(DataTemplate), typeof(DragDrop), new PropertyMetadata((DataTemplate)null)); /// /// Gets a EffectAdorner DataTemplate for effect type All. /// public static DataTemplate GetEffectAllAdornerTemplate(UIElement target) { return (DataTemplate)target.GetValue(EffectAllAdornerTemplateProperty); } /// /// Sets a EffectAdorner DataTemplate for effect type All. /// public static void SetEffectAllAdornerTemplate(UIElement target, DataTemplate value) { target.SetValue(EffectAllAdornerTemplateProperty, value); } /// /// Gets or Sets a EffectAdorner DataTemplate for effect type Scroll. /// public static readonly DependencyProperty EffectScrollAdornerTemplateProperty = DependencyProperty.RegisterAttached("EffectScrollAdornerTemplate", typeof(DataTemplate), typeof(DragDrop), new PropertyMetadata((DataTemplate)null)); /// /// Gets a EffectAdorner DataTemplate for effect type Scroll. /// public static DataTemplate GetEffectScrollAdornerTemplate(UIElement target) { return (DataTemplate)target.GetValue(EffectScrollAdornerTemplateProperty); } /// /// Sets a EffectAdorner DataTemplate for effect type Scroll. /// public static void SetEffectScrollAdornerTemplate(UIElement target, DataTemplate value) { target.SetValue(EffectScrollAdornerTemplateProperty, value); } /// /// Gets or Sets the Orientation which should be used for the drag drop action (default null). /// Normally it will be look up to find the correct orientaion of the inner ItemsPanel, /// but sometimes it's necessary to force the oreintation, if the look up is wrong. /// public static readonly DependencyProperty ItemsPanelOrientationProperty = DependencyProperty.RegisterAttached("ItemsPanelOrientation", typeof(Orientation?), typeof(DragDrop), new PropertyMetadata(null)); /// /// Gets the Orientation which should be used for the drag drop action (default null). /// Normally it will be look up to find the correct orientaion of the inner ItemsPanel, /// but sometimes it's necessary to force the oreintation, if the look up is wrong. /// public static Orientation? GetItemsPanelOrientation(UIElement source) { return (Orientation?)source.GetValue(ItemsPanelOrientationProperty); } /// /// Sets the Orientation which should be used for the drag drop action (default null). /// Normally it will be look up to find the correct orientaion of the inner ItemsPanel, /// but sometimes it's necessary to force the oreintation, if the look up is wrong. /// public static void SetItemsPanelOrientation(UIElement source, Orientation? value) { source.SetValue(ItemsPanelOrientationProperty, value); } /// /// Gets or sets the minimum horizontal drag distance to allow for limited movement of the mouse pointer before a drag operation begins. /// Default is SystemParameters.MinimumHorizontalDragDistance. /// public static readonly DependencyProperty MinimumHorizontalDragDistanceProperty = DependencyProperty.RegisterAttached("MinimumHorizontalDragDistance", typeof(double), typeof(DragDrop), new PropertyMetadata(SystemParameters.MinimumHorizontalDragDistance)); /// /// Sets the minimum horizontal drag distance. /// public static double GetMinimumHorizontalDragDistance(UIElement source) { return (double)source.GetValue(MinimumHorizontalDragDistanceProperty); } /// /// Sets the minimum horizontal drag distance. /// public static void SetMinimumHorizontalDragDistance(UIElement source, double value) { source.SetValue(MinimumHorizontalDragDistanceProperty, value); } /// /// Gets or sets the minimum vertical drag distance to allow for limited movement of the mouse pointer before a drag operation begins. /// Default is SystemParameters.MinimumVerticalDragDistance. /// public static readonly DependencyProperty MinimumVerticalDragDistanceProperty = DependencyProperty.RegisterAttached("MinimumVerticalDragDistance", typeof(double), typeof(DragDrop), new PropertyMetadata(SystemParameters.MinimumVerticalDragDistance)); /// /// Gets the minimum vertical drag distance. /// public static double GetMinimumVerticalDragDistance(UIElement source) { return (double)source.GetValue(MinimumVerticalDragDistanceProperty); } /// /// Sets the minimum vertical drag distance. /// public static void SetMinimumVerticalDragDistance(UIElement source, double value) { source.SetValue(MinimumVerticalDragDistanceProperty, value); } /// /// Gets or sets whether if the dropped items should be select again (should keep the selection). /// Default is false. /// public static readonly DependencyProperty SelectDroppedItemsProperty = DependencyProperty.RegisterAttached("SelectDroppedItems", typeof(bool), typeof(DragDrop), new PropertyMetadata(false)); /// /// Gets whether if the dropped items should be select again (should keep the selection). /// public static bool GetSelectDroppedItems(UIElement target) { return (bool)target.GetValue(SelectDroppedItemsProperty); } /// /// Sets whether if the dropped items should be select again (should keep the selection). /// public static void SetSelectDroppedItems(UIElement target, bool value) { target.SetValue(SelectDroppedItemsProperty, value); } /// /// Gets or sets the that will be used as . /// public static readonly DependencyProperty DropTargetScrollViewerProperty = DependencyProperty.RegisterAttached("DropTargetScrollViewer", typeof(ScrollViewer), typeof(DragDrop), new PropertyMetadata((ScrollViewer)null)); /// /// Sets the that will be used as . /// public static void SetDropTargetScrollViewer(DependencyObject element, ScrollViewer value) { element.SetValue(DropTargetScrollViewerProperty, value); } /// /// Gets the that will be used as . /// public static ScrollViewer GetDropTargetScrollViewer(DependencyObject element) { return (ScrollViewer)element?.GetValue(DropTargetScrollViewerProperty); } } }