Esempio n. 1
0
        private static void OnDrop(object _sender, DragEventArgs _dragEventArgs)
        {
            if (!(_sender is DependencyObject d))
            {
                return;
            }
            object          target     = d.GetValue(FileDragDropTargetProperty);
            IDragDropTarget fileTarget = target as IDragDropTarget;

            if (fileTarget != null)
            {
                if (_dragEventArgs.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    fileTarget.OnFileDrop((string[])_dragEventArgs.Data.GetData(DataFormats.FileDrop));
                }
                else if (_dragEventArgs.Data.GetDataPresent(DataFormats.Text))
                {
                    fileTarget.OnTextDrop((string)_dragEventArgs.Data.GetData(DataFormats.Text));
                }
            }
            else
            {
                throw new Exception("FileDragDropTarget object must be of type IFileDragDropTarget");
            }
        }
Esempio n. 2
0
        private static void TargetChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            DependencyObject Element       = sender as DependencyObject;
            IDragDropTarget  NewTarget     = e.NewValue as IDragDropTarget;
            IDragDropTarget  CurrentTarget = e.OldValue as IDragDropTarget;

            if (Element is UIElement || Element is ContentElement)
            {
                if (CurrentTarget != null)
                {
                    DragDropTargetAdapter Adapter;
                    DragDrop.dragDropTargets.TryGetValue(Element, out Adapter).DbC_Assure(isSuccess => isSuccess);
                    DragDrop.dragDropTargets.Remove(Element);
                    Adapter?.Dispose();
                }

                if (NewTarget != null)
                {
                    DragDropTargetAdapter Adapter = DragDropTargetAdapter.Create(NewTarget, Element, true);
                    DragDrop.dragDropTargets.Add(Element, Adapter);
                }
            }
            else
            {
                throw new InvalidOperationException("Drag and Drop target can only be registered on UIElements and ContentElements");
            }
        }
Esempio n. 3
0
        //private readonly Popup popup = new Popup();
        //private Point dragLocation;

        private DragDropTargetAdapter(IDragDropTarget targetHandler, DependencyObject target, bool makeDroppable)
        {
            this.targetHandler     = targetHandler;
            this.target            = target;
            this.dragTargetHandler = DragDrop.GetDragDropUITargetHandler(target.GetType()).Create(target, this, makeDroppable);

            System.Windows.DragDrop.AddDragEnterHandler(this.target, this.DragEnter);
            System.Windows.DragDrop.AddDragLeaveHandler(this.target, this.DragLeave);
            System.Windows.DragDrop.AddDragOverHandler(this.target, this.DragOver);
            System.Windows.DragDrop.AddDropHandler(this.target, this.Drop);


            /*
             *  this.popup.AllowsTransparency = true;
             *  ContentControl Content = new ContentControl();
             *  Content.SetBinding(ContentControl.ContentProperty, "");
             *  Border Border = new Border();
             *  Border.BorderThickness = new Thickness(1);
             *  Border.CornerRadius = new CornerRadius(3);
             *  Border.BorderBrush = new SolidColorBrush(SystemColors.HighlightColor) { Opacity = 0.7 };
             *  Border.Background = new SolidColorBrush(SystemColors.HighlightColor) {Opacity = 0.3};
             *  Border.Child = Content;
             *  Border.MinHeight = 10;
             *  Border.MinWidth = 10;
             *  this.popup.Child = Border;
             *  this.popup.Placement = PlacementMode.Custom;
             *  this.popup.CustomPopupPlacementCallback = this.HandlePopupPlacement;
             *  this.popup.HorizontalOffset = 10;
             *  this.popup.VerticalOffset = 10;*/
        }
        private static void OnDrop(object _sender, DragEventArgs _dragEventArgs)
        {
            DependencyObject d = _sender as DependencyObject;

            if (d == null)
            {
                return;
            }
            Object          target     = d.GetValue(DragDropTargetProperty);
            IDragDropTarget dropTarget = target as IDragDropTarget;

            if (dropTarget != null)
            {
                if (_dragEventArgs.Data.GetDataPresent(DataFormats.Html))
                {
                    dropTarget.OnHtmlDrop((object)_dragEventArgs.Data.GetData(DataFormats.Html));
                }
                else if (_dragEventArgs.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    dropTarget.OnFileDrop((string[])_dragEventArgs.Data.GetData(DataFormats.FileDrop));
                }
            }
            else
            {
                throw new Exception("DragDropTarget object must be of type IDragDropTarget");
            }
        }
Esempio n. 5
0
        private static void OnDragOver(object sender, DragEventArgs e)
        {
            if (!(sender is DependencyObject d))
            {
                return;
            }
            object          target     = d.GetValue(FileDragDropTargetProperty);
            IDragDropTarget fileTarget = target as IDragDropTarget;

            if (fileTarget != null)
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    var filenames = ((string[])e.Data.GetData(DataFormats.FileDrop));
                    foreach (var filename in filenames)
                    {
                        string c = Path.GetExtension(filename);
                        if (c == ".xls" || c == ".xlsm" || c == ".xlsx")
                        {
                            e.Effects = DragDropEffects.Move;
                        }
                        else
                        {
                            e.Effects = DragDropEffects.None;
                            break;
                        }
                    }
                    e.Handled = true;
                }
            }
        }
Esempio n. 6
0
 static bool TryGetAsDragDropTarget <T>(
     object obj,
     [MaybeNullWhen(false)] out IDragDropTarget <T> target)
 {
     if (obj is ISourceList <T> sourceList)
     {
         target = new SourceListDragDropTarget <T>(sourceList);
         return(true);
     }
     if (obj is ISourceListUiFunnel <T> funnel)
     {
         target = new SourceListDragDropTarget <T>(funnel.SourceList);
         return(true);
     }
     if (obj is IDerivativeSelectedCollection <T> derivative)
     {
         target = new DerivativeListDragDropTarget <T>(derivative);
         return(true);
     }
     if (obj is IList <T> l)
     {
         target = new ListDragDropTarget <T>(l);
         return(true);
     }
     target = default;
     return(false);
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dimensions"></param>
        /// <param name="dropZoneOffsets"></param>
        protected DropZoneBase(IDragDropTarget source, Rect dimensions, Thickness dropZoneOffsets)
        {
            Source = source;
            TargetDimensions = dimensions;
            DropZoneOffsets = dropZoneOffsets;
            HotSpot = _defaultHotSpot;

            Canvas.SetLeft(HotSpot, dimensions.Left);
            Canvas.SetTop(HotSpot, dimensions.Top);
            HotSpot.Width = dimensions.Width;
            HotSpot.Height = dimensions.Height;
            DropZoneUI = HotSpot;
        }
        /// <summary>
        /// Unregisters a IDragDropTarget from the manager
        /// </summary>
        /// <param name="dragDropTarget"></param>
        public void UnRegisterDragDropTarget(IDragDropTarget dragDropTarget)
        {
            if (dragDropTarget == null) throw new ArgumentNullException("dragDropTarget");

            if (_targets.Contains(dragDropTarget))
                _targets.Remove(dragDropTarget);
        }
        /// <summary>
        /// Registers a IDragDropTarget to the manager
        /// </summary>
        /// <param name="dragDropTarget"></param>
        public void RegisterDragDropTarget(IDragDropTarget dragDropTarget)
        {
            if (dragDropTarget == null) throw new ArgumentNullException("dragDropTarget");

            _targets.Add(dragDropTarget);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="source"></param>
 /// <param name="dimensions"></param>
 /// <param name="dropZoneOffsets"></param>
 public DefaultDropZone(IDragDropTarget source, Rect dimensions, Thickness dropZoneOffsets)
     : base(source, dimensions, dropZoneOffsets)
 {
     ((Grid)HotSpot).Background = new SolidColorBrush(Colors.Transparent);
 }
Esempio n. 11
0
 ///<summary>
 /// Registers a drag and drop target handler for a given UI element
 ///</summary>
 public static void SetTarget(DependencyObject element, IDragDropTarget target)
 {
     element.SetValue(DragDrop.TargetProperty, target);
 }
 public EdgeDockingDropZone(InsertType insertType, IDragDropTarget source, Rect dimensions, Thickness dropZoneOffsets)
     : base(source, dimensions, dropZoneOffsets)
 {
     _insertType = insertType;
     InitUIProperties();
 }
 public InsertingDropZone(IDragDropTarget source, Rect dimensions, bool isHorizontal, Thickness dropZoneOffsets)
     : base(source, dimensions, dropZoneOffsets)
 {
     _isHorizontal = isHorizontal;
     InitUIProperties();
 }
Esempio n. 14
0
 public static DragDropTargetAdapter Create(IDragDropTarget dragDropTarget, DependencyObject dependencyObject, bool makeDroppable)
 {
     return(new DragDropTargetAdapter(dragDropTarget, dependencyObject, makeDroppable));
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="source"></param>
 /// <param name="dimensions"></param>
 /// <param name="dropZoneOffsets"></param>
 public HighlightingDropZone(IDragDropTarget source, Rect dimensions, Thickness dropZoneOffsets)
     : base(source, dimensions, dropZoneOffsets)
 {
     Init();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="source"></param>
 /// <param name="dimensions"></param>
 /// <param name="dropZoneOffsets"></param>
 /// <param name="highlightBrush"></param>
 public HighlightingDropZone(IDragDropTarget source, Rect dimensions, Thickness dropZoneOffsets, Brush highlightBrush)
     : base(source, dimensions, dropZoneOffsets)
 {
     _targetVisual.BorderBrush = highlightBrush;
     Init();
 }
        protected const byte TargetVisualTransparancy = 125; // lower is more transparent

        #endregion Fields

        #region Constructors

        protected LUCADropZoneBase(IDragDropTarget source, Rect dimensions, Thickness dropZoneOffsets)
            : base(source, dimensions, dropZoneOffsets)
        {
        }