System.Windows.Input.MouseEventArgs.GetPosition(System.Windows.IInputElement)

Here are the examples of the csharp api System.Windows.Input.MouseEventArgs.GetPosition(System.Windows.IInputElement) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

913 Examples 7

19 Source : SeriesVerticalSlicesExample.xaml.cs
with MIT License
from ABTSoftware

private void OnCreateSliceClick(object sender, RoutedEventArgs e)
        {
            MouseButtonEventHandler mouseClick = null;

            mouseClick = (s, arg) =>
            {
                MouseLeftButtonUp -= mouseClick;

                var mousePoint = arg.GetPosition((UIElement)sciChart.GridLinesPanel).X;

                var slice = new VerticalLineAnnotation()
                {
                    X1 = sciChart.XAxis.GetDataValue(mousePoint),
                    Style = (Style)Resources["sliceStyle"]
                };

                sliceModifier.VerticalLines.Add(slice);
            };

            MouseLeftButtonUp += mouseClick;
        }

19 Source : HitTestDatapoints.xaml.cs
with MIT License
from ABTSoftware

private void SciChartSurfaceMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            // Perform the hit test relative to the GridLinesPanel
            var hitTestPoint = e.GetPosition(sciChartSurface.GridLinesPanel as UIElement);

            // Show info for series, which HitTest operation was successful for only
            foreach(var renderableSeries in sciChartSurface.RenderableSeries)
            {
                // Get hit-test the RenderableSeries using interpolation
                var hitTestInfo = renderableSeries.HitTestProvider.HitTest(hitTestPoint, true);

                if (hitTestInfo.Ireplaced)
                {
                    // Convert the result of hit-test operation to SeriesInfo
                    var seriesInfo = renderableSeries.GetSeriesInfo(hitTestInfo);

                    // Output result
                    var formattedString = SeriesInfoToFormattedString(seriesInfo, hitTestPoint);

                    // Show result
                    Console.WriteLine(formattedString);
                    AddOnView(formattedString);
                }
            }
        }

19 Source : BoxAnnotation3D.cs
with MIT License
from ABTSoftware

private void Surface_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			var mousePosition = e.GetPosition(currentSurface);
			HitTestInfo3D hitTestInfo = currentSurface.RenderableSeries.First().HitTest(mousePosition);
			
			if (hitTestInfo.EnreplacedyId == EnreplacedyId)
			{
				_dragFaceId = (int)hitTestInfo.VertexId;
				var faceCenter = getFaceCenter(_dragFaceId);
				_dragVector = getRelativePoint(faceCenter, _normals[_dragFaceId], mousePosition);
				
				e.Handled = true;
				currentSurface.CaptureMouse();
				refresh();
			}
		}

19 Source : BoxAnnotation3D.cs
with MIT License
from ABTSoftware

private void CurrentSurface_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
		{
			var mousePosition = e.GetPosition(currentSurface);
			if (_dragVector != null)
			{
				var faceCenter = getFaceCenter(_dragFaceId);
				var newDragVector = getRelativePoint(faceCenter, _normals[_dragFaceId], mousePosition);
				var delta = newDragVector - _dragVector;

				moveFace(_dragFaceId, delta);

				if (Keyboard.Modifiers == ModifierKeys.Control)
					moveFace(oppositeFace(_dragFaceId), delta * -1);
				else if (Keyboard.Modifiers == ModifierKeys.Shift)
					moveFace(oppositeFace(_dragFaceId), delta);

				_dragVector = newDragVector;
				e.Handled = true;
			}
		}

19 Source : HitTestToAddAnnotations.xaml.cs
with MIT License
from ABTSoftware

private void Scs_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            // Get mouse point
            var mousePoint = e.GetPosition(scs);

            // Transform point to inner viewport 
            // https://www.scichart.com/questions/question/how-can-i-convert-xyaxis-value-to-chart-surface-coodinate
            // https://www.scichart.com/doreplacedentation/v5.x/Axis%20APIs%20-%20Convert%20Pixel%20to%20Data%20Coordinates.html
            mousePoint = scs.RootGrid.TranslatePoint(mousePoint, scs.ModifierSurface);

            // Convert the mousePoint.X to x DataValue using axis
            var xDataValue = scs.XAxis.GetDataValue(mousePoint.X);

            // Create a vertical line annotation at the mouse point 
            scs.Annotations.Add(new VerticalLineAnnotation() { X1 = xDataValue});
        }

19 Source : MainControl.xaml.cs
with MIT License
from Actipro

private void OnFindResultsTextBoxDoubleClick(object sender, MouseButtonEventArgs e) {
			// Quit if there is no editor or result set stored yet
			var editor = findResultsToolWindow.DataContext as SyntaxEditor;
			var resultSet = findResultsTextBox.DataContext as ISearchResultSet;
			if ((editor == null) || (resultSet == null))
				return;

			int charIndex = findResultsTextBox.GetCharacterIndexFromPoint(e.GetPosition(findResultsTextBox), true);
			int lineIndex = findResultsTextBox.GetLineIndexFromCharacterIndex(charIndex);

			int resultIndex = lineIndex - 1;  // Account for first line in results displaying search info
			if ((resultIndex >= 0) && (resultIndex < resultSet.Results.Count)) {
				// A valid result was clicked
				ISearchResult result = resultSet.Results[resultIndex];
				if (result.ReplaceSnapshotRange.IsDeleted) {
					// Find result
					editor.ActiveView.Selection.SelectRange(result.FindSnapshotRange.TranslateTo(editor.ActiveView.CurrentSnapshot, TextRangeTrackingModes.Default).TextRange);
				}
				else {
					// Replace result
					editor.ActiveView.Selection.SelectRange(result.ReplaceSnapshotRange.TranslateTo(editor.ActiveView.CurrentSnapshot, TextRangeTrackingModes.Default).TextRange);
				}

				// Focus the editor
				editor.Focus();
			}
		}

19 Source : MainControl.xaml.cs
with MIT License
from Actipro

private void OnPreviewMouseUp(object sender, MouseButtonEventArgs e) {
			// If a selection was just made with the mouse...
			if ((e.ChangedButton == MouseButton.Left) && (!editor.Selection.IsEmpty)) {
				// Get the mini-toolbar in the resources of this UserControl
				RibbonControls.MiniToolBar toolBar = (RibbonControls.MiniToolBar)this.FindResource("SimpleMiniToolBar");
				if (toolBar != null) {
					// Show the mini-toolbar
					MiniToolBarService.Show(toolBar, editor, e.GetPosition(editor));
				}
			}
		}

19 Source : RichTextBoxExtended.cs
with MIT License
from Actipro

protected override void OnMouseUp(MouseButtonEventArgs e) {
			// Call the base method
			base.OnMouseUp(e);

			// If a selection was just made with the mouse and we are not in an XBAP...
			if ((e.ChangedButton == MouseButton.Left) && (!this.Selection.IsEmpty) && (!BrowserInteropHelper.IsBrowserHosted)) {
				// Show the mini-toolbar
				MiniToolBarService.Show(new ActiproSoftware.ProductSamples.RibbonSamples.Common.RichTextBoxMiniToolBar(), 
					this, e.GetPosition(this));
			}
		}

19 Source : MainControl.xaml.cs
with MIT License
from Actipro

private void OnResultsTextBoxDoubleClick(object sender, MouseButtonEventArgs e) {
			// Quit if there is not result set stored yet
			if (lastResultSet == null)
				return;

			int charIndex = resultsTextBox.GetCharacterIndexFromPoint(e.GetPosition(resultsTextBox), true);
			int lineIndex = resultsTextBox.GetLineIndexFromCharacterIndex(charIndex);

			int resultIndex = lineIndex - 1;  // Account for first line in results displaying search info
			if ((resultIndex >= 0) && (resultIndex < lastResultSet.Results.Count)) {
				// A valid result was clicked
				ISearchResult result = lastResultSet.Results[resultIndex];
				if (result.ReplaceSnapshotRange.IsDeleted) {
					// Find result
					editor.ActiveView.Selection.SelectRange(result.FindSnapshotRange.TranslateTo(editor.ActiveView.CurrentSnapshot, TextRangeTrackingModes.Default).TextRange);
				}
				else {
					// Replace result
					editor.ActiveView.Selection.SelectRange(result.ReplaceSnapshotRange.TranslateTo(editor.ActiveView.CurrentSnapshot, TextRangeTrackingModes.Default).TextRange);
				}

				// Focus the editor
				editor.Focus();
			}
		}

19 Source : MainControl.xaml.cs
with MIT License
from Actipro

private void OnFindResultsTextBoxDoubleClick(object sender, MouseButtonEventArgs e) {
			// Quit if there is not result set stored yet
			if (lastResultSet == null)
				return;

			int charIndex = findResultsTextBox.GetCharacterIndexFromPoint(e.GetPosition(findResultsTextBox), true);
			int lineIndex = findResultsTextBox.GetLineIndexFromCharacterIndex(charIndex);

			int resultIndex = lineIndex - 1;  // Account for first line in results displaying search info
			if ((resultIndex >= 0) && (resultIndex < lastResultSet.Results.Count)) {
				// A valid result was clicked
				ISearchResult result = lastResultSet.Results[resultIndex];
				if (result.ReplaceSnapshotRange.IsDeleted) {
					// Find result
					syntaxEditor.ActiveView.Selection.SelectRange(result.FindSnapshotRange.TranslateTo(syntaxEditor.ActiveView.CurrentSnapshot, TextRangeTrackingModes.Default).TextRange);
				}
				else {
					// Replace result
					syntaxEditor.ActiveView.Selection.SelectRange(result.ReplaceSnapshotRange.TranslateTo(syntaxEditor.ActiveView.CurrentSnapshot, TextRangeTrackingModes.Default).TextRange);
				}

				// Focus the editor
				syntaxEditor.Focus();
			}
		}

19 Source : MainControl.xaml.cs
with MIT License
from Actipro

private void OnSyntaxEditorMouseMove(object sender, MouseEventArgs e) {
			IHitTestResult result = editor.HitTest(e.GetPosition(editor));
			this.UpdateHitTestInfo(result);
		}

19 Source : MainControl.xaml.cs
with MIT License
from Actipro

private void OnProductListBoxItemMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
			// Don't start dragging if a button has the capture, since it's probably being pressed
			if (!(Mouse.Captured is ButtonBase)) {
				ProductListBoxItem item = (ProductListBoxItem)sender;
				if (item.CaptureMouse()) {
					this.dragPoint = e.GetPosition(item.Parent as Panel);
					this.dragLeft = AnimatedCanvas.GetLeft(item);
					this.dragTop = AnimatedCanvas.GetTop(item);
					e.Handled = true;
				}
			}
		}

19 Source : MainControl.xaml.cs
with MIT License
from Actipro

private void OnProductListBoxItemMouseMove(object sender, MouseEventArgs e) {
			ProductListBoxItem item = (ProductListBoxItem)sender;
			if (this.dragPoint != null && item.IsMouseCaptured) {
				// Get the current point and the difference with the drag point
				Point currentPoint = e.GetPosition(item.Parent as Panel);
				double diffX = currentPoint.X - this.dragPoint.Value.X;
				double diffY = currentPoint.Y - this.dragPoint.Value.Y;

				// Ensure the mouse has moved a minimum distance
				if (Math.Abs(diffX) >= 3 || Math.Abs(diffY) >= 3) {
					AnimatedCanvas.SetLeft(item, this.dragLeft + diffX);
					AnimatedCanvas.SetTop(item, this.dragTop + diffY);
					e.Handled = true;
				}
			}
		}

19 Source : DataGridPartEditBoxColumnBase.cs
with MIT License
from Actipro

protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs) {
			var editBox = editingElement as PartEditBoxBase<T>;
			if (editBox == null)
				return null;

			editBox.Focus();
			var uneditedValue = editBox.Value;

			var mouseArgs = editingEventArgs as MouseButtonEventArgs;
			if (IsMouseLeftButtonDown(mouseArgs)) {
				// Declare and implement the filter callback method
				HitTestFilterCallback filterCallback = new HitTestFilterCallback(delegate(DependencyObject target) {
					FrameworkElement element = target as FrameworkElement;
					if ((element != null) && (element.IsVisible) && (element is DropDownButton)) {
						if (!editBox.IsPopupOpen)
							editBox.IsPopupOpen = true;
						return HitTestFilterBehavior.Stop;
					}
					return HitTestFilterBehavior.Continue;
				});

				// Declare and implement the result callback method, which simply defaults to returning Stop
				HitTestResultCallback resultCallback = new HitTestResultCallback(delegate(HitTestResult result) {
					return HitTestResultBehavior.Stop;
				});

				// Perform the hit-testing starting with the Breadcrumb control
				VisualTreeHelper.HitTest(editBox, filterCallback, resultCallback, new PointHitTestParameters(mouseArgs.GetPosition(editBox)));
			}

			return uneditedValue;
		}

19 Source : DateTimePicker.xaml.cs
with MIT License
from ADeltaX

void TickClick()
        {
			tickingCount++;

			if (tickingCount == 1)
				tickingSpeed = 125;
			else if (tickingCount == 3)
				tickingSpeed = 60;
			else if (tickingCount == 6)
				tickingSpeed = 40;
			else if (tickingCount == 10)
				tickingSpeed = 16;

			dispatcherTimer.Interval = TimeSpan.FromMilliseconds(tickingSpeed);

			if (Click != null)
			{
				bool up = mouseButtonEventArgs.GetPosition(AdornedElement).Y < (_top + _bottom) / 2;
				Click((TextBox)AdornedElement, up ? 1 : -1);
			}
		}

19 Source : ObjectTracker.cs
with GNU General Public License v3.0
from ahmed605

private void OnMouseDown(object sender, MouseEventArgs e)
        {
            Mouse.Capture(EventSource, CaptureMode.Element);
            _previousPosition2D = e.GetPosition(EventSource);
        }

19 Source : ObjectTracker.cs
with GNU General Public License v3.0
from ahmed605

private void OnMouseMove(object sender, MouseEventArgs e)
        {
            Point currentPosition = e.GetPosition(EventSource);

            // Prefer tracking to zooming if both buttons are pressed.
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                Track(currentPosition);
            }
            else if (e.RightButton == MouseButtonState.Pressed)
            {
                Zoom(currentPosition);
            }

            _previousPosition2D = currentPosition;
        }

19 Source : CanvasCamera.cs
with MIT License
from alaabenfatma

protected virtual void HandleMouseMove(object sender, MouseEventArgs e)
        {
            var v = Start - e.GetPosition(this);

            if (MouseMode == MouseMode.Panning)
            {
                TranslateTransform.X = Origin.X - v.X;
                TranslateTransform.Y = Origin.Y - v.Y;

                for (var index = 0; index < Children.Count; index++)
                {
                    var element = Children[index];
                    if (element is Wire) continue;
                    if (element is Node)
                    {
                        var node = element as Node;
                        node.X = node.X - v.X;
                        node.Y = node.Y - v.Y;
                    }
                }
                Start = e.GetPosition(this);
            }
            else if (MouseMode == MouseMode.Selection)
            {
                for (var index = 0; index < SelectedNodes.Count; index++)
                {
                    var child = SelectedNodes[index];
                    child.X = child.X - v.X;
                    child.Y = child.Y - v.Y;
                }

                Start = e.GetPosition(this);
            }
            if (SelectedComment != null)
            {
                SelectedComment.X = SelectedComment.X - v.X;
                SelectedComment.Y = SelectedComment.Y - v.Y;
                Start = e.GetPosition(this);
            }
        }

19 Source : VirtualControl.cs
with MIT License
from alaabenfatma

private void OnMouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
        {
            if (Nodes?.Count > 0) Keyboard.Focus(Nodes[0]);
            if (mouseButtonEventArgs.ChangedButton == MouseButton.Left && mouseButtonEventArgs.ClickCount == 2)
            {
                if (!Children.Contains(NodesTree))
                    NodesTree.Show();
                MouseMode = MouseMode.PreSelectionRectangle;
            }
            else if (mouseButtonEventArgs.LeftButton == MouseButtonState.Pressed)
            {
                _startPoint = mouseButtonEventArgs.GetPosition(this);

                if (Children.Contains(_selectionZone))
                    Children.Remove(_selectionZone);

                _selectionZone = new Border
                {
                    BorderBrush = Brushes.WhiteSmoke,
                    BorderThickness = new Thickness(2),
                    CornerRadius = new CornerRadius(6)
                };

                SetLeft(_selectionZone, _startPoint.X);
                SetTop(_selectionZone, _startPoint.X);

                MouseMode = MouseMode.SelectionRectangle;
                WireMode = WireMode.Nothing;
            }
        }

19 Source : VirtualControl.cs
with MIT License
from alaabenfatma

private void OnMouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            if (WireMode == WireMode.FirstPortSelected && MouseMode == MouseMode.DraggingPort)
            {
                TempConn.EndPoint = new Point(mouseEventArgs.GetPosition(this).X - 1,
                    mouseEventArgs.GetPosition(this).Y);
                if (_wiresDisabled) return;
                for (var index = 0; index < Children.Count - 1; index++)
                {
                    var uielement = Children[index];
                    if (uielement is Wire)
                        MagicLaboratory.GrayWiresOut(uielement as Wire);
                }
                _wiresDisabled = true;
                return;
            }
            if (mouseEventArgs.LeftButton == MouseButtonState.Released)
                if (_wiresDisabled)
                {
                    for (var index = 0; index < Children.Count - 1; index++)
                    {
                        var uielement = Children[index];
                        if (uielement is Wire)
                            MagicLaboratory.GrayWiresOut_Reverse(uielement as Wire);
                    }
                    _wiresDisabled = false;
                }

            if (mouseEventArgs.LeftButton != MouseButtonState.Released && MouseMode == MouseMode.SelectionRectangle)
            {
                if (!Children.Contains(_selectionZone))
                    AddChildren(_selectionZone);
                var pos = mouseEventArgs.GetPosition(this);
                var x = Math.Min(pos.X, _startPoint.X);
                var y = Math.Min(pos.Y, _startPoint.Y);
                var w = Math.Max(pos.X, _startPoint.X) - x;
                var h = Math.Max(pos.Y, _startPoint.Y) - y;
                _selectionZone.Width = w;
                _selectionZone.Height = h;
                SetLeft(_selectionZone, x);
                SetTop(_selectionZone, y);
                SelectionZoneWorkerOnDoWork();
                return;
            }
            if (MouseMode == MouseMode.ResizingComment && mouseEventArgs.LeftButton == MouseButtonState.Pressed)
            {
                Cursor = Cursors.SizeNWSE;
                var currentPoint = Mouse.GetPosition(this);
                if (currentPoint.Y - TempComment.Y > 0 && currentPoint.X - TempComment.X > 0)
                {
                    TempComment.Height = /*TempComment.Top +*/ currentPoint.Y - TempComment.Y;
                    TempComment.Width = /* TempComment.Left +*/ currentPoint.X - TempComment.X;
                    TempComment.LocateHandler();
                }
                else
                {
                    TempComment.Height = 32;
                    TempComment.Width = 32;
                    TempComment.LocateHandler();
                }
                return;
            }
            if (NeedsRefresh)
            {
                foreach (var node in Nodes)
                    node.Refresh();

                TemExecPort = null;
                TemObjectPort = null;
                NeedsRefresh = false;
            }
        }

19 Source : CanvasCamera.cs
with MIT License
from alaabenfatma

protected virtual void HandleMouseDown(object sender, MouseButtonEventArgs e)
        {
            Start = e.GetPosition(this);
            Origin = new Point(TranslateTransform.X, TranslateTransform.Y);
            if (MouseMode != MouseMode.Selection && e.ChangedButton == MouseButton.Middle)
            {
                Cursor = Cursors.Hand;
                MouseMode = MouseMode.Panning;
            }
        }

19 Source : ZoomBorder.cs
with GNU General Public License v3.0
from alexdillon

private void Child_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (this.child != null)
            {
                var st = this.GetScaleTransform(this.child);
                var tt = this.GetTranslateTransform(this.child);

                if (st == null || tt == null)
                {
                    return;
                }

                double zoom = e.Delta > 0 ? .2 : -.2;
                if (!(e.Delta > 0) && (st.ScaleX < .4 || st.ScaleY < .4))
                {
                    return;
                }

                Point relative = e.GetPosition(this.child);
                double absoluteX;
                double absoluteY;

                absoluteX = (relative.X * st.ScaleX) + tt.X;
                absoluteY = (relative.Y * st.ScaleY) + tt.Y;

                st.ScaleX += zoom;
                st.ScaleY += zoom;

                tt.X = absoluteX - (relative.X * st.ScaleX);
                tt.Y = absoluteY - (relative.Y * st.ScaleY);

                if (st.ScaleX < 1.0 || st.ScaleY < 1.0)
                {
                    if (!Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.RightCtrl))
                    {
                        st.ScaleX = 1.0;
                        st.ScaleY = 1.0;

                        tt.X = 0;
                        tt.Y = 0;
                    }
                }
            }
        }

19 Source : ZoomBorder.cs
with GNU General Public License v3.0
from alexdillon

private void Child_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (this.child != null)
            {
                var tt = this.GetTranslateTransform(this.child);
                this.start = e.GetPosition(this);
                this.origin = new Point(tt.X, tt.Y);
                this.Cursor = Cursors.Hand;
                this.child.CaptureMouse();
            }
        }

19 Source : ZoomBorder.cs
with GNU General Public License v3.0
from alexdillon

private void Child_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.child != null)
            {
                if (this.child.IsMouseCaptured)
                {
                    var tt = this.GetTranslateTransform(this.child);
                    if (tt == null)
                    {
                        return;
                    }

                    Vector v = this.start - e.GetPosition(this);
                    tt.X = this.origin.X - v.X;
                    tt.Y = this.origin.Y - v.Y;
                }
            }
        }

19 Source : MainWindow.xaml.cs
with GNU General Public License v3.0
from AndrasMumm

private void modListView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Get current mouse position
            startPoint = e.GetPosition(null);
        }

19 Source : MainWindow.xaml.cs
with GNU General Public License v3.0
from AndrasMumm

private void modListView_MouseMove(object sender, MouseEventArgs e)
        {
            // Get the current mouse position
            Point mousePos = e.GetPosition(null);
            Vector diff = startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                       Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                Debug.WriteLine("Here--");
                InDragAndDropOperation = true;
                // Get the dragged ListViewItem
                ListView listView = sender as ListView;
                ListViewItem listViewItem = FindAnchestor<ListViewItem>((DependencyObject)e.OriginalSource);
                if (listViewItem == null) return;           // Abort
                                                            // Find the data behind the ListViewItem
                ModInfo item = (ModInfo)listView.ItemContainerGenerator.ItemFromContainer(listViewItem);
                if (item == null) return;                   // Abort
                                                            // Initialize the drag & drop operation
                startIndex = modListView.SelectedIndex;
                DataObject dragData = new DataObject("ModInfo", item);

                DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Copy | DragDropEffects.Move);
            }
        }

19 Source : NotepadListItem.xaml.cs
with MIT License
from AngryCarrot789

private void GripLeftMouseButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                GripMouseStartPoint = e.GetPosition(null);
        }

19 Source : NotepadListItem.xaml.cs
with MIT License
from AngryCarrot789

private void GripMouseMove(object sender, MouseEventArgs e)
        {
            bool canDrag;
            if (PreferencesG.USE_NEW_DRAGDROP_SYSTEM && !Model.Notepad.Doreplacedent.FilePath.IsFile())
            {
                Cursor = Cursors.Hand;
                canDrag = true;
            }
            else
            {
                Cursor = Cursors.No;
                canDrag = false;
            }

            if (GripMouseStartPoint != e.GetPosition(null) && e.LeftButton == MouseButtonState.Pressed)
            {
                try
                {
                    if (canDrag)
                    {
                        SetDraggingStatus(true);
                        DragDropFileWatchers.DoingDragDrop(Model.Notepad);
                        string prefixedPath = Path.Combine(Path.GetTempPath(), DragDropNameHelper.GetPrefixedFileName(Model.Notepad.Doreplacedent.FileName));
                        string[] fileList = new string[] { prefixedPath };
                        File.WriteAllText(prefixedPath, Model.Notepad.Doreplacedent.Text);
                        DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, fileList), DragDropEffects.Move);
                        SetDraggingStatus(false);
                    }
                }
                catch { }
            }
        }

19 Source : NotepadListItem.xaml.cs
with MIT License
from AngryCarrot789

private void Grid_MouseMove(object sender, MouseEventArgs e)
        {
            // Wrapping the entire thing in a try catch block just incase
            // Had to add a check to the textbox because it can freeze the entire UI
            // if you click and drag over the textbox. idk why though, calls a COM exception.
            if (CanStartDragDrop())
            {
                try
                {
                    Point orgPos = ControlMouseStartPoint;
                    Point newPos = e.GetPosition(this);
                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        bool canDoDrag = false;
                        int mouseXDragOffset = 16;
                        int mouseYDragOffset = 10;
                        int edgeOffsetX = 10, edgeOffsetY = 10;

                        // Checks if you drag a bit awawy from where you clicked.
                        if (newPos.X < (orgPos.X - mouseXDragOffset) || newPos.X > (orgPos.X + mouseXDragOffset))
                            canDoDrag = true;
                        if (newPos.Y < (orgPos.Y - mouseYDragOffset) || newPos.Y > (orgPos.Y + mouseYDragOffset))
                            canDoDrag = true;

                        // Checks if you drag near to the edges of the border.
                        if (newPos.X < edgeOffsetX || newPos.X > (ActualWidth - edgeOffsetX))
                            canDoDrag = true;
                        if (newPos.Y < edgeOffsetY || newPos.Y > (ActualHeight - edgeOffsetY))
                            canDoDrag = true;

                        if (canDoDrag)
                        {
                            if (Model.Notepad.Doreplacedent.FilePath.IsFile())
                            {
                                string[] path1 = new string[1] { Model.Notepad.Doreplacedent.FilePath };
                                SetDraggingStatus(true);
                                DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, path1), DragDropEffects.Copy);
                                SetDraggingStatus(false);
                            }
                            else
                            {
                                SetDraggingStatus(true);
                                string tempFilePath = Path.Combine(Path.GetTempPath(), Model.Notepad.Doreplacedent.FileName);
                                File.WriteAllText(tempFilePath, Model.Notepad.Doreplacedent.Text);
                                string[] path = new string[1] { tempFilePath };
                                DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, path), DragDropEffects.Copy);
                                File.Delete(tempFilePath);
                                SetDraggingStatus(false);
                            }
                        }
                    }
                }
                catch { }
            }
        }

19 Source : NotepadListItem.xaml.cs
with MIT License
from AngryCarrot789

private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                ControlMouseStartPoint = e.GetPosition(this);
        }

19 Source : TopNotepadListItem.xaml.cs
with MIT License
from AngryCarrot789

private void Grid_MouseMove(object sender, MouseEventArgs e)
        {
            // Wrapping the entire thing in a try catch block just incase
            // Had to add a check to the textbox because it can freeze the entire UI
            // if you click and drag over the textbox. idk why though, calls a COM exception.
            if (!IsDragging && !fileNameBox.IsMouseOver && !fileNameBox.IsFocused)
            {
                try
                {
                    Point orgPos = ControlMouseStartPoint;
                    Point newPos = e.GetPosition(this);
                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        bool canDoDrag = false;
                        int mouseXDragOffset = 24;
                        int mouseYDragOffset = 20;
                        int edgeOffsetX = 10, edgeOffsetY = 10;

                        // Checks if you drag a bit awawy from where you clicked.
                        if (newPos.X < (orgPos.X - mouseXDragOffset) || newPos.X > (orgPos.X + mouseXDragOffset))
                            canDoDrag = true;
                        if (newPos.Y < (orgPos.Y - mouseYDragOffset) || newPos.Y > (orgPos.Y + mouseYDragOffset))
                            canDoDrag = true;

                        // Checks if you drag near to the edges of the border.
                        if (newPos.X < edgeOffsetX || newPos.X > (ActualWidth - edgeOffsetX))
                            canDoDrag = true;
                        if (newPos.Y < edgeOffsetY || newPos.Y > (ActualHeight - edgeOffsetY))
                            canDoDrag = true;

                        if (canDoDrag)
                        {
                            if (Model.Notepad.Doreplacedent.FilePath.IsFile())
                            {
                                string[] path1 = new string[1] { Model.Notepad.Doreplacedent.FilePath };
                                SetDraggingStatus(true);
                                DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, path1), DragDropEffects.Copy);
                                SetDraggingStatus(false);
                            }
                            else
                            {
                                SetDraggingStatus(true);
                                string tempFilePath = Path.Combine(Path.GetTempPath(), Model.Notepad.Doreplacedent.FileName);
                                File.WriteAllText(tempFilePath, Model.Notepad.Doreplacedent.Text);
                                string[] path = new string[1] { tempFilePath };
                                DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, path), DragDropEffects.Copy);
                                File.Delete(tempFilePath);
                                SetDraggingStatus(false);
                            }
                        }
                    }
                }
                catch { }
            }
        }

19 Source : NotepadWindow.xaml.cs
with MIT License
from AngryCarrot789

private void TreeViewItem_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                MouseDownPoint = e.GetPosition(null);
        }

19 Source : NotepadWindow.xaml.cs
with MIT License
from AngryCarrot789

private void TreeViewItem_MouseMove(object sender, MouseEventArgs e)
        {
            if (MouseDownPoint != e.GetPosition(null) && e.LeftButton == MouseButtonState.Pressed)
            {
                // Found that with treeviewitems, the sender's parent's datacontext is the FileSystemObjectInfo
                if (sender is Rectangle grip && grip.Parent is StackPanel fileItem)
                {
                    if (fileItem.DataContext is FileSystemObjectInfo file)
                    {
                        try
                        {
                            if (File.Exists(file.FileSystemInfo.FullName))
                            {
                                string[] path1 = new string[1] { file.FileSystemInfo.FullName };
                                DragDrop.DoDragDrop(
                                    this,
                                    new DataObject(DataFormats.FileDrop, path1),
                                    DragDropEffects.Copy);
                            }
                        }
                        catch { }
                    }
                }
            }
        }

19 Source : DicomPanelView.xaml.cs
with Apache License 2.0
from anmcgrath

private void DicomPanelView_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if(e.LeftButton == MouseButtonState.Pressed)
                Model?.OnMouseDown(getWorldPoint(e.GetPosition(this)));
        }

19 Source : DicomPanelView.xaml.cs
with Apache License 2.0
from anmcgrath

private void DicomPanelView_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if(e.LeftButton == MouseButtonState.Released)
                Model?.OnMouseUp(getWorldPoint(e.GetPosition(this)));
        }

19 Source : DicomPanelView.xaml.cs
with Apache License 2.0
from anmcgrath

private void DicomPanelView_MouseMove(object sender, MouseEventArgs e)
        {
            Model?.OnMouseMove(getWorldPoint(e.GetPosition(this)));
        }

19 Source : DicomPanelView.xaml.cs
with Apache License 2.0
from anmcgrath

private void DicomPanelView_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            Model?.OnMouseScroll(getWorldPoint(e.GetPosition(this)), e.Delta);
        }

19 Source : DicomPanelView.xaml.cs
with Apache License 2.0
from anmcgrath

private void Grid_MouseLeave(object sender, MouseEventArgs e)
        {
            Model?.OnMouseExit(getWorldPoint(e.GetPosition(this)));
        }

19 Source : DicomPanelView.xaml.cs
with Apache License 2.0
from anmcgrath

private void Grid_MouseEnter(object sender, MouseEventArgs e)
        {
            Model?.OnMouseEnter(getWorldPoint(e.GetPosition(this)));
        }

19 Source : LUTController.xaml.cs
with Apache License 2.0
from anmcgrath

private void canvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (topTriangleMouseDown)
            {
                var posn = e.GetPosition(this);
                if (posn.Y < 0)
                    posn.Y = 0;
                UpperValue = Max - (Min + ((posn.Y - offset) / canvas.Height) * (Max - Min));
            }
        }

19 Source : LUTController.xaml.cs
with Apache License 2.0
from anmcgrath

private void topTriangleShape_MouseDown(object sender, MouseButtonEventArgs e)
        {
            topTriangleMouseDown = true;
            offset = e.GetPosition(this).Y - Canvas.GetTop(this.topTriangleShape);
            Mouse.Capture(canvas);
        }

19 Source : WebViewOverlay.xaml.cs
with MIT License
from anoyetta

private void ImageView_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var image = sender as Image;

            image.CaptureMouse();
            var tt = (TranslateTransform)((TransformGroup)image.RenderTransform)
                .Children.First(tr => tr is TranslateTransform);
            this.start = e.GetPosition(this.ImageBorder);
            this.origin = new Point(tt.X, tt.Y);
        }

19 Source : WebViewOverlay.xaml.cs
with MIT License
from anoyetta

private void ImageView_MouseMove(object sender, MouseEventArgs e)
        {
            var image = sender as Image;

            if (image.IsMouseCaptured)
            {
                var tt = (TranslateTransform)((TransformGroup)image.RenderTransform)
                    .Children.First(tr => tr is TranslateTransform);
                var v = start - e.GetPosition(this.ImageBorder);
                tt.X = origin.X - v.X;
                tt.Y = origin.Y - v.Y;
            }
        }

19 Source : MediaWindow.xaml.cs
with MIT License
from AntonyCorbett

private void BrowserGrid_MouseMove(object? sender, System.Windows.Input.MouseEventArgs e)
        {
            var pos = e.GetPosition(this);
            _webNavHeaderAdmin.MouseMove(pos);
        }

19 Source : MainWindow.xaml.cs
with MIT License
from AntonyCorbett

private void DragSourcePreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (sender is Control card)
            {
                var vm = (MainViewModel)DataContext;
                vm.DragSourcePreviewMouseDown(card, e.GetPosition(null));
            }
        }

19 Source : MainWindow.xaml.cs
with MIT License
from AntonyCorbett

private void DragSourcePreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                var position = e.GetPosition(null);

                var vm = (MainViewModel)DataContext;
                vm.DragSourcePreviewMouseMove(position);
            }
        }

19 Source : AyTableViewSelector.cs
with MIT License
from ay2015

private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (!isScrollerBar)
            {
                if (Mouse.LeftButton == MouseButtonState.Pressed)
                {
                    var _1 = e.GetPosition(this.scrollContent);
                    if (!isDragSelect && firstpoint!=null)
                    {
                        if (Math.Abs(_1.X - firstpoint.Value.X) > 40 || Math.Abs(_1.Y - firstpoint.Value.Y) > 40) //AY 2017-12-6 16:37:14
                        {
                            isDragSelect = true;
                            if ((firstpoint.Value.X >= 0) && (firstpoint.Value.X < this.scrollContent.ActualWidth) &&
                                (firstpoint.Value.Y >= 0) && (firstpoint.Value.Y < this.scrollContent.ActualHeight))
                            {
                                this.mouseCaptured = this.scrollContent.CaptureMouse();

                                this.StartSelection(firstpoint.Value);
                            }
                        }
                    }
                    if (this.mouseCaptured)
                    {
                        this.end = _1;
                        this.autoScroller.Update(this.end);
                        this.UpdateSelection();
                    }
                }
            }
        }

19 Source : DragInCanvasBehavior.cs
with MIT License
from ay2015

void replacedociatedObject_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            //获得canvas
            if (canvas == null)
            {
                canvas = (Canvas)VisualTreeHelper.GetParent(this.replacedociatedObject);
                //canvas.SizeChanged += canvas_SizeChanged;
            }
            isDragging = true;
            mouseOffset = e.GetPosition(this.replacedociatedObject);
            tempHeight = (double)this.replacedociatedObject.GetValue(FrameworkElement.HeightProperty);
            tempWidth = (double)this.replacedociatedObject.GetValue(FrameworkElement.WidthProperty);
            this.replacedociatedObject.CaptureMouse();
        }

19 Source : DragInGridBehavior.cs
with MIT License
from ay2015

private void ExecuteMode(System.Windows.Input.MouseEventArgs e)
        {
            Point point = e.GetPosition(dl);
            double endSetY = point.Y - mouseOffset.Y;
            double endSetX = point.X - mouseOffset.X;
            if (endSetY < 0) endSetY = 0;
            if (endSetX < 0) endSetX = 0;

            if (endSetY > dl.ActualHeight-40)
            {
                endSetY = dl.ActualHeight - 40;
            }
            if (endSetX > dl.ActualWidth - 140)
            {
                endSetX = dl.ActualWidth - 140;
            }
            ne.Top = endSetY;
            ne.Left = endSetX;
            ne.Right = 0;
            ne.Bottom = 0;
    
            bd.SetValue(Border.MarginProperty, ne);
        }

19 Source : DragInGridBehavior.cs
with MIT License
from ay2015

void replacedociatedObject_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            //获得canvas
            if (bd == null)
            {
                //bd = ((this.replacedociatedObject as FrameworkElement).Parent as FrameworkElement).Parent as Border;
                dl = (this.replacedociatedObject as FrameworkElement).GetLogicalAncestor<AyLayer>();
                if (dl == null)
                {
                    dl = (this.replacedociatedObject as FrameworkElement).GetVisualAncestor<AyLayer>();
                }
          
                if (dl != null)
                {
                    bd = (dl.Content as Grid).FindChild("body", typeof(Border)) as Border;
                }
             (this.replacedociatedObject as FrameworkElement).Cursor = Cursors.SizeAll;
                //canvas.SizeChanged += canvas_SizeChanged;
            }
            if (dl.DragreplacedleBarStart != null)
            {
                dl.DragreplacedleBarStart();
            }
            isDragging = true;
            mouseOffset = e.GetPosition(this.bd);
            tempHeight = (double)this.bd.GetValue(FrameworkElement.ActualHeightProperty);
            tempWidth = (double)this.bd.GetValue(FrameworkElement.ActualWidthProperty);
            this.replacedociatedObject.CaptureMouse();
        }

See More Examples