Beispiel #1
0
        Walkabout.Utilities.DragDropSource OnDragSource(object source)
        {
            Walkabout.Utilities.DragDropSource returnSource = null;

            ListBoxItem listBoxItemControl = WpfHelper.FindAncestor <ListBoxItem>((DependencyObject)source);

            if (listBoxItemControl != null)
            {
                Payee payee = listBoxItemControl.Content as Payee;
                if (payee != null)
                {
                    returnSource                       = new DragDropSource();
                    returnSource.DataSource            = payee;
                    returnSource.VisualForDraginSource = listBoxItemControl;
                }
            }

            return(returnSource);
        }
Beispiel #2
0
        Walkabout.Utilities.DragDropSource OnDragSource(object source)
        {
            Walkabout.Utilities.DragDropSource returnSource = null;

            ListBoxItem listBoxItemControl = WpfHelper.FindAncestor <ListBoxItem>((DependencyObject)source);

            if (listBoxItemControl != null)
            {
                Security x = listBoxItemControl.Content as Security;
                if (x != null)
                {
                    returnSource                       = new DragDropSource();
                    returnSource.DataSource            = x;
                    returnSource.VisualForDraginSource = CreateDragVisual(x);
                }
            }

            return(returnSource);
        }
        Walkabout.Utilities.DragDropSource OnDragDropObjectSource(object source)
        {
            Walkabout.Utilities.DragDropSource returnSource = null;

            if (IsEditing)
            {
                // turn off drag when in editing mode
            }
            else
            {
                TreeViewItem treeViewItem = WpfHelper.FindAncestor <TreeViewItem>((DependencyObject)source);
                if (treeViewItem != null)
                {
                    // First child of a TreeViewItem seems to always be a Grid in all Themes
                    FrameworkElement grid = VisualTreeHelper.GetChild(treeViewItem, 0) as FrameworkElement;
                    if (grid != null)
                    {
                        //
                        // The grid has 2 child
                        // 0 = Expander
                        // 1 = Tree Node visual
                        //
                        //
                        // We want the TreeNode visual without the Expander
                        FrameworkElement representationOfTheTreeNodeToDrag = VisualTreeHelper.GetChild(grid, 1) as FrameworkElement;
                        if (representationOfTheTreeNodeToDrag != null)
                        {
                            Category category = treeViewItem.Header as Category;
                            if (category != null)
                            {
                                returnSource                       = new DragDropSource();
                                returnSource.DataSource            = category;
                                returnSource.VisualForDraginSource = representationOfTheTreeNodeToDrag;
                            }
                        }
                    }
                }
            }

            return(returnSource);
        }
Beispiel #4
0
        private void StartDrag(MouseEventArgs e, DragDropSource objectBeenDragged)
        {
            DestroyDragDropWindow();

            this.isDragging = true;

            GiveFeedbackEventHandler feedbackHandler = new GiveFeedbackEventHandler(OnDragSourceGiveFeedback);;

            this.mainControl.GiveFeedback += feedbackHandler;

            QueryContinueDragEventHandler queryContinueHandler = new QueryContinueDragEventHandler(OnDragSourceQueryContinueDrag);

            this.mainControl.QueryContinueDrag += queryContinueHandler;


            try
            {
                if (objectBeenDragged.VisualForDraginSource == null)
                {
                    objectBeenDragged.VisualForDraginSource = new Rectangle();
                }

                CreateDragDropWindow(objectBeenDragged.VisualForDraginSource);


                // Initialize the drag & drop operation
                DataObject dragData = new DataObject(formatName, objectBeenDragged.DataSource);
                DragDrop.DoDragDrop(this.mainControl, dragData, DragDropEffects.Move | DragDropEffects.Copy);
            }
            catch
            {
            }
            finally
            {
                this.isDragging = false;
                DestroyDragDropWindow();
                this.mainControl.GiveFeedback      -= feedbackHandler;
                this.mainControl.QueryContinueDrag -= queryContinueHandler;
            }
        }
Beispiel #5
0
        void OnPreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (this.isMouseDown == false)
            {
                return;
            }

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                // Get the current mouse position
                Point  mousePos = e.GetPosition(this.mainControl);
                Vector diff     = this.dragStartPoint - mousePos;

                if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
                {
                    // Find out if we have a acceptable object instance behind for the UIElement being dragged
                    DragDropSource validObjectToDrag = calledBackForValidatingSource(dragSourceStartedFrom);
                    if (validObjectToDrag != null)
                    {
                        StartDrag(e, validObjectToDrag);
                    }
                }
            }
        }