Exemplo n.º 1
0
        private bool IsMouseOverType <CTRL>() where CTRL : Control
        {
            Point         ptMouse = User32Mouse.GetMousePosition(this.listView);
            HitTestResult res     = VisualTreeHelper.HitTest(this.listView, ptMouse);

            if (res == null)
            {
                return(false);
            }

            DependencyObject depObj = res.VisualHit;

            while (depObj != null)
            {
                if (depObj is CTRL)
                {
                    return(true);
                }

                // VisualTreeHelper works with objects of type Visual or Visual3D.
                // If the current object is not derived from Visual or Visual3D,
                // then use the LogicalTreeHelper to find the parent element.
                if (depObj is Visual || depObj is System.Windows.Media.Media3D.Visual3D)
                {
                    depObj = VisualTreeHelper.GetParent(depObj);
                }
                else
                {
                    depObj = LogicalTreeHelper.GetParent(depObj);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        void listView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (this.IsMouseOverScrollbar || this.IsMouseOverTextBox)
            {
                // 4/13/2007 - Set the flag to false when cursor is over scrollbar.
                this.canInitiateDrag = false;
                return;
            }

            int index = this.IndexUnderDragCursor;

            this.canInitiateDrag = index > -1;

            if (this.canInitiateDrag)
            {
                // Remember the location and index of the ListViewItem the user clicked on for later.
                this.ptMouseDown   = User32Mouse.GetMousePosition(this.listView);
                this.indexToSelect = index;
            }
            else
            {
                this.ptMouseDown   = new Point(-10000, -10000);
                this.indexToSelect = -1;
            }
        }
Exemplo n.º 3
0
        void UpdateDragAdornerLocation()
        {
            if (this.dragAdorner != null)
            {
                Point ptCursor = User32Mouse.GetMousePosition(this.ListView);

                double left = ptCursor.X - this.ptMouseDown.X;

                // 4/13/2007 - Made the top offset relative to the item being dragged.
                ListViewItem itemBeingDragged = this.GetListViewItem(this.indexToSelect);
                Point        itemLoc          = itemBeingDragged.TranslatePoint(new Point(0, 0), this.ListView);
                double       top = itemLoc.Y + ptCursor.Y - this.ptMouseDown.Y;

                this.dragAdorner.SetOffsets(left, top);
            }
        }
Exemplo n.º 4
0
        bool IsMouseOver(Visual target)
        {
            if (target == null)
            {
                return(false);
            }

            // We need to use MouseUtilities to figure out the cursor
            // coordinates because, during a drag-drop operation, the WPF
            // mechanisms for getting the coordinates behave strangely.

            Rect  bounds   = VisualTreeHelper.GetDescendantBounds(target);
            Point mousePos = User32Mouse.GetMousePosition(target);

            return(bounds.Contains(mousePos));
        }
Exemplo n.º 5
0
        AdornerLayer InitializeAdornerLayer(ListViewItem itemToDrag)
        {
            // Create a brush which will paint the ListViewItem onto
            // a visual in the adorner layer.
            VisualBrush brush = new VisualBrush(itemToDrag);

            // Create an element which displays the source item while it is dragged.
            this.dragAdorner = new DragAdorner(this.listView, itemToDrag.RenderSize, brush);

            // Set the drag adorner's opacity.
            this.dragAdorner.Opacity = this.DragAdornerOpacity;

            AdornerLayer layer = AdornerLayer.GetAdornerLayer(this.listView);

            layer.Add(dragAdorner);

            // Save the location of the cursor when the left mouse button was pressed.
            this.ptMouseDown = User32Mouse.GetMousePosition(this.listView);

            return(layer);
        }