コード例 #1
0
        /// <summary>
        /// Handles the MouseLeftButtonDown of the drag source. Starts the dragging operation.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The envet args instance containing event data.</param>
        private void DragSource_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.dragSource.CaptureMouse();

            if (!this.IsDragging)
            {
                DataTemplate dragTemplate = DragDropManager.GetDragTemplate(this.dragSource);
                object       dragData     = DragDropManager.GetDragData(this.dragSource);

                this.DragPopupChild.Children.Clear();
                this.IsDragging = true;

                DragDropControl dragDropControl = new DragDropControl
                {
                    DragContent  = dragData,
                    DragTemplate = dragTemplate
                };

                this.DragPopupChild.Children.Add(dragDropControl);

                if (!this.DragPopup.IsOpen)
                {
                    this.DragPopupChild.Opacity = 0;
                    this.DragPopup.IsOpen       = true;
                }

                this.ShowDragDrop(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Toggles the drop allowed value of the current drag drop control.
        /// </summary>
        /// <param name="dropAllowed">If the drop is allowed or not.</param>
        private void ShowDragDrop(bool dropAllowed)
        {
            if (this.DragPopup != null && this.DragPopupChild != null && this.IsDragging)
            {
                if (this.DragPopupChild.Children.Count > 0)
                {
                    DragDropControl dragDropControl = this.DragPopupChild.Children[0] as DragDropControl;

                    if (dragDropControl != null)
                    {
                        dragDropControl.DropAllowed = dropAllowed;
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Check if there are drop zones an specific position.
        /// </summary>
        /// <param name="e">The mouse event args.</param>
        /// <returns>A list of possible drop zones.</returns>
        private IList <FrameworkElement> CheckDropZones(MouseEventArgs e)
        {
            IList <FrameworkElement> dropZonesAtCurrentCord = new List <FrameworkElement>();

            if (this.DragPopup != null && this.DragPopupChild != null && this.DragPopupChild.Children.Count > 0)
            {
                DragDropControl dragDropControl = this.DragPopupChild.Children[0] as DragDropControl;

                if (dragDropControl != null)
                {
                    IList <FrameworkElement> invalidDropZones = new List <FrameworkElement>();
                    foreach (FrameworkElement frameworkElement in DragDropManager.DropZones)
                    {
                        IDropInfo dropInfo       = DragDropManager.GetDropInfo(frameworkElement);
                        Type      dragSourceType = dragDropControl.DragContent.GetType();
                        try
                        {
                            Point dropPoint = e.GetPosition(frameworkElement);

                            if ((dropPoint.X >= 0 && dropPoint.X <= frameworkElement.ActualWidth) &&
                                (dropPoint.Y >= 0 && dropPoint.Y <= frameworkElement.ActualHeight) &&
                                dropInfo.AllowedDragTypes.Contains(dragSourceType))
                            {
                                dropZonesAtCurrentCord.Add(frameworkElement);
                            }
                        }
                        catch (Exception)
                        {
                            invalidDropZones.Add(frameworkElement);
                        }
                    }

                    foreach (FrameworkElement element in invalidDropZones)
                    {
                        DragDropManager.DropZones.Remove(element);
                    }

                    invalidDropZones.Clear();
                }
            }

            return(dropZonesAtCurrentCord);
        }
コード例 #4
0
        /// <summary>
        /// Check if there are drop zones an specific position.
        /// </summary>
        /// <param name="e">The mouse event args.</param>
        /// <returns>A list of possible drop zones.</returns>
        private FrameworkElement GetDropZone(MouseEventArgs e)
        {
            IList <FrameworkElement> dropZonesAtCurrentCord = new List <FrameworkElement>();

            if (this.DragPopup != null && this.DragPopupChild != null && this.DragPopupChild.Children.Count > 0)
            {
                DragDropControl dragDropControl = this.DragPopupChild.Children[0] as DragDropControl;

                if (dragDropControl != null)
                {
                    IList <FrameworkElement> invalidDropZones = new List <FrameworkElement>();
                    foreach (FrameworkElement frameworkElement in DragDropManager.DropZones)
                    {
                        IDropInfo dropInfo       = DragDropManager.GetDropInfo(frameworkElement);
                        Type      dragSourceType = dragDropControl.DragContent.GetType();
                        try
                        {
                            Point dropPoint = e.GetPosition(frameworkElement);

                            if (frameworkElement.Visibility == Visibility.Visible &&
                                frameworkElement.ActualHeight != 0 &&
                                frameworkElement.ActualWidth != 0 &&
                                (dropPoint.X >= 0 && dropPoint.X <= frameworkElement.ActualWidth) &&
                                (dropPoint.Y >= 0 && dropPoint.Y <= frameworkElement.ActualHeight) &&
                                dropInfo.AllowedDragTypes.Contains(dragSourceType))
                            {
                                dropZonesAtCurrentCord.Add(frameworkElement);
                            }
                        }
                        catch (Exception)
                        {
                            invalidDropZones.Add(frameworkElement);
                        }
                    }

                    foreach (FrameworkElement element in invalidDropZones)
                    {
                        DragDropManager.DropZones.Remove(element);
                    }

                    invalidDropZones.Clear();
                }
            }

            int maxIndex = -1;

            FrameworkElement topMostDropZone = null;

            foreach (FrameworkElement dropZone in dropZonesAtCurrentCord)
            {
                FloatableWindow parentWindow = dropZone.GetParentControl <FloatableWindow>();

                int canvasZIndex = Canvas.GetZIndex(parentWindow);

                if (canvasZIndex > maxIndex)
                {
                    maxIndex        = canvasZIndex;
                    topMostDropZone = dropZone;
                }
            }

            return(topMostDropZone);
        }