bool _IsMouseOver(Visual target) { // 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. if (target != null) { Rect bounds = VisualTreeHelper.GetDescendantBounds(target); Point mousePos = MouseUtilities.GetMousePosition(target); return(bounds.Contains(mousePos)); } else { return(false); } }
void DraggableListView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { 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 = MouseUtilities.GetMousePosition(listView); this.indexToSelect = index; } else { this.ptMouseDown = new Point(-10000, -10000); this.indexToSelect = -1; } }