Example #1
0
        private static void PreviewDragStartCommandPropertyChangedCallBack(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            var visual = o as FrameworkElement;

            if (visual != null)
            {
                visual.PreviewMouseLeftButtonDown += (sender, args) =>
                {
                    DragDropHelpers.LastMouseDownVisual = visual;
                    DragDropHelpers.LastMouseDown       = args.GetPosition(null);
                    var itemsControl = visual as System.Windows.Controls.ItemsControl;
                    if (itemsControl != null)
                    {
                        if (MultiSelectDragDropBehavior.GetAllowMultiSelectDragDrop(itemsControl))
                        {
                            MultiSelectDragDropBehavior.ItemsControlPreviewMouseLeftButtonDown(itemsControl, args);
                        }
                    }
                };

                visual.MouseMove += (sender, args) =>
                {
                    if (!DragDropHelpers.InDragOperation && (DragDropHelpers.LastMouseDownVisual == visual) && (args.LeftButton == System.Windows.Input.MouseButtonState.Pressed))
                    {
                        try
                        {
                            DragDropHelpers.InDragOperation = DragDropHelpers.DragStarted(args.GetPosition(null));
                            if (DragDropHelpers.InDragOperation)
                            {
                                var command = GetPreviewDragStartCommand(visual);
                                if (command.CanExecute(args))
                                {
                                    command.Execute(args);
                                    var dragData     = new DataObject(command.Format, command.Data);
                                    var itemsControl = visual as System.Windows.Controls.ItemsControl;
                                    if ((itemsControl != null) && DragDropRearrangeBehavior.GetAllowsDragDropRearrange(itemsControl))
                                    {
                                        dragData.SetData(DragDropHelpers.DragDropFeedbackDataFormat, new DragDropFeedback());
                                    }
                                    var effects = DragDrop.DoDragDrop(visual, dragData, command.Effects);
                                    if (dragData.GetDataPresent(DragDropHelpers.DragDropFeedbackDataFormat))
                                    {
                                        var dragDropFeedback = dragData.GetData(DragDropHelpers.DragDropFeedbackDataFormat) as IDragDropFeedback;
                                        if (dragDropFeedback != null)
                                        {
                                            dragDropFeedback.DropLocation = DropOnItemLocation.None;
                                        }
                                        INTV.Shared.View.DropItemLocationAdorner.Update(visual, dragDropFeedback, true);
                                    }
                                }
                            }
                        }
                        finally
                        {
                            DragDropHelpers.InDragOperation = false;
                        }
                    }
                };
            }
        }
Example #2
0
        private static void HandleDrop(object sender, DragEventArgs args)
        {
            var visual = sender as UIElement;

            GetDropCommand(visual).Execute(args);
            var itemsControl = visual as System.Windows.Controls.ItemsControl;

            if ((itemsControl != null) && DragDropRearrangeBehavior.GetAllowsDragDropRearrange(itemsControl))
            {
                var dragDropFeedback = args.Data.GetData(DragDropHelpers.DragDropFeedbackDataFormat) as IDragDropFeedback;
                if (dragDropFeedback != null)
                {
                    dragDropFeedback.DropLocation = DropOnItemLocation.None;
                }
                INTV.Shared.View.DropItemLocationAdorner.Update(itemsControl, dragDropFeedback, true);
            }
            args.Handled = true;
        }
Example #3
0
        private static void HandleDragOver(object sender, DragEventArgs args)
        {
            var visual = sender as FrameworkElement;
            IDragDropFeedback dragDropFeedback = null;

            if (args.Data.GetDataPresent(DragDropHelpers.DragDropFeedbackDataFormat))
            {
                dragDropFeedback = args.Data.GetData(DragDropHelpers.DragDropFeedbackDataFormat) as IDragDropFeedback;
            }
            else
            {
                var itemsControl    = visual as System.Windows.Controls.ItemsControl;
                var allowsRearrange = (itemsControl != null) && DragDropRearrangeBehavior.GetAllowsDragDropRearrange(itemsControl);
                if (allowsRearrange)
                {
                    dragDropFeedback = new DragDropFeedback();
                    args.Data.SetData(DragDropHelpers.DragDropFeedbackDataFormat, dragDropFeedback);
                }
            }
            if (dragDropFeedback != null)
            {
                var height       = visual.ActualHeight;
                var location     = args.GetPosition(visual);
                var dropLocation = GetDropLocation(visual, location);
                dragDropFeedback.DropLocation = dropLocation;
            }
            GetDragOverCommand(visual).Execute(args);
            if (dragDropFeedback != null)
            {
                if (args.Effects == DragDropEffects.None)
                {
                    dragDropFeedback.DropLocation = DropOnItemLocation.None;
                }
                DropItemLocationAdorner.Update(visual, dragDropFeedback, false);
            }
            args.Handled = true;
        }