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
19
Source : DragDrop.cs
with Microsoft Public License
from Dijji
with Microsoft Public License
from Dijji
private static void DragSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// Ignore the click if clickCount != 1 or the user has clicked on a scrollbar.
var elementPosition = e.GetPosition((IInputElement)sender);
if (e.ClickCount != 1
|| HitTestUtilities.HitTest4Type<RangeBase>(sender, elementPosition)
|| HitTestUtilities.HitTest4Type<TextBoxBase>(sender, elementPosition)
|| HitTestUtilities.HitTest4Type<PreplacedwordBox>(sender, elementPosition)
|| HitTestUtilities.HitTest4Type<ComboBox>(sender, elementPosition)
|| HitTestUtilities.HitTest4GridViewColumnHeader(sender, elementPosition)
|| HitTestUtilities.HitTest4DataGridTypes(sender, elementPosition)
|| HitTestUtilities.IsNotPartOfSender(sender, e)
|| GetDragSourceIgnore((UIElement)sender)) {
m_DragInfo = null;
return;
}
m_DragInfo = new DragInfo(sender, e);
var dragHandler = TryGetDragHandler(m_DragInfo, sender as UIElement);
if (!dragHandler.CanStartDrag(m_DragInfo)) {
m_DragInfo = null;
return;
}
// If the sender is a list box that allows multiple selections, ensure that clicking on an
// already selected item does not change the selection, otherwise dragging multiple items
// is made impossible.
var itemsControl = sender as ItemsControl;
if (m_DragInfo.VisualSourceItem != null && itemsControl != null && itemsControl.CanSelectMultipleItems()) {
var selectedItems = itemsControl.GetSelectedItems().Cast<object>();
if (selectedItems.Count() > 1 && selectedItems.Contains(m_DragInfo.SourceItem)) {
m_ClickSupressItem = m_DragInfo.SourceItem;
e.Handled = true;
}
}
}
19
Source : DragDrop.cs
with Microsoft Public License
from Dijji
with Microsoft Public License
from Dijji
private static void DragSource_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (m_DragInfo != null && !m_DragInProgress) {
// do nothing if mouse left button is released
if (e.LeftButton == MouseButtonState.Released)
{
m_DragInfo = null;
return;
}
var dragStart = m_DragInfo.DragStartPosition;
var position = e.GetPosition((IInputElement)sender);
if (Math.Abs(position.X - dragStart.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(position.Y - dragStart.Y) > SystemParameters.MinimumVerticalDragDistance) {
var dragHandler = TryGetDragHandler(m_DragInfo, sender as UIElement);
if (dragHandler.CanStartDrag(m_DragInfo)) {
dragHandler.StartDrag(m_DragInfo);
if (m_DragInfo.Effects != DragDropEffects.None && m_DragInfo.Data != null) {
var data = m_DragInfo.DataObject;
if (data == null) {
data = new DataObject(DataFormat.Name, m_DragInfo.Data);
} else {
data.SetData(DataFormat.Name, m_DragInfo.Data);
}
try {
m_DragInProgress = true;
var result = System.Windows.DragDrop.DoDragDrop(m_DragInfo.VisualSource, data, m_DragInfo.Effects);
if (result == DragDropEffects.None)
dragHandler.DragCancelled();
}
finally {
m_DragInProgress = false;
}
m_DragInfo = null;
}
}
}
}
}
19
Source : HitTestUtilities.cs
with Microsoft Public License
from Dijji
with Microsoft Public License
from Dijji
public static bool IsNotPartOfSender(object sender, MouseButtonEventArgs e)
{
var visual = e.OriginalSource as Visual;
if (visual == null) {
return false;
}
var hit = VisualTreeHelper.HitTest(visual, e.GetPosition((IInputElement)visual));
if (hit == null) {
return false;
} else {
var depObj = e.OriginalSource as DependencyObject;
if (depObj == null) {
return false;
}
var item = VisualTreeHelper.GetParent(depObj.FindVisualTreeRoot());
//var item = VisualTreeHelper.GetParent(e.OriginalSource as DependencyObject);
while (item != null && item != sender) {
item = VisualTreeHelper.GetParent(item);
}
return item != sender;
}
}
19
Source : RangeScrollbar.xaml.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
private void _PART_RangeOverlay_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
// The user should still be able to use right mouse button (context menu)
if ((e.LeftButton == MouseButtonState.Pressed) == false)
return;
// The user should still be able to drag the thumb to update displays in synced fashion
if (sender != this || _ThumbIsDragging == true)
return;
IInputElement inputElement = Mouse.DirectlyOver;
// Lets keep the thumb draggable by ignoring thumb mouse clicks here
var thumbMousover = _PART_Track.Thumb.InputHitTest(e.GetPosition(_PART_Track.Thumb));
if (thumbMousover != null)
return;
// Find the percentage value where the mouse click occurred on the track
Point p = e.GetPosition(_PART_Track);
// Filter out clicks on repeat button (or other elements below or above Track)
if (Orientation == Orientation.Vertical)
{
if (p.Y > _PART_Track.ActualHeight || p.Y < 0)
return;
double factor = p.Y / _PART_Track.ActualHeight;
// Convert the percentage value into the actual value scale
double targetValue = Math.Abs(Maximum - Minimum) * factor;
this.Value = Minimum + targetValue;
e.Handled = true;
}
else
{
if (Orientation == Orientation.Horizontal)
{
if (p.X > _PART_Track.ActualWidth || p.X < 0)
return;
double factor = p.X / _PART_Track.ActualWidth;
// Convert the percentage value into the actual value scale
double targetValue = Math.Abs(Maximum - Minimum) * factor;
this.Value = Minimum + targetValue;
e.Handled = true;
}
}
}
19
Source : LayoutDocumentTabItem.cs
with Microsoft Public License
from Dirkster99
with Microsoft Public License
from Dirkster99
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
_allowDrag = false;
Model.IsActive = true;
if (Model is LayoutDoreplacedent layoutDoreplacedent && !layoutDoreplacedent.CanMove) return;
if (e.ClickCount != 1) return;
_mouseDownPoint = e.GetPosition(this);
_isMouseDown = true;
}
19
Source : LayoutDocumentTabItem.cs
with Microsoft Public License
from Dirkster99
with Microsoft Public License
from Dirkster99
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
_isMouseDown = Mouse.LeftButton == MouseButtonState.Pressed && _isMouseDown;
if (_isMouseDown)
{
var ptMouseMove = e.GetPosition(this);
CaptureMouse();
if (Math.Abs(ptMouseMove.X - _mouseDownPoint.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(ptMouseMove.Y - _mouseDownPoint.Y) > SystemParameters.MinimumVerticalDragDistance)
{
UpdateDragDetails();
_isMouseDown = false;
_allowDrag = true;
}
}
if (!IsMouseCaptured || !_allowDrag) return;
var mousePosInScreenCoord = this.PointToScreenDPI(e.GetPosition(this));
if (!_parentDoreplacedentTabPanelScreenArea.Contains(mousePosInScreenCoord))
StartDraggingFloatingWindowForContent();
else
{
var indexOfTabItemWithMouseOver = _otherTabsScreenArea.FindIndex(r => r.Contains(mousePosInScreenCoord));
if (indexOfTabItemWithMouseOver < 0) return;
var targetModel = _otherTabs[indexOfTabItemWithMouseOver].Content as LayoutContent;
var container = Model.Parent as ILayoutContainer;
var containerPane = Model.Parent as ILayoutPane;
if (containerPane is LayoutDoreplacedentPane layoutDoreplacedentPane && !layoutDoreplacedentPane.CanRepositionItems) return;
if (containerPane.Parent is LayoutDoreplacedentPaneGroup layoutDoreplacedentPaneGroup && !layoutDoreplacedentPaneGroup.CanRepositionItems) return;
var childrenList = container.Children.ToList();
containerPane.MoveChild(childrenList.IndexOf(Model), childrenList.IndexOf(targetModel));
Model.IsActive = true;
_parentDoreplacedentTabPanel.UpdateLayout();
UpdateDragDetails();
}
}
19
Source : ColorCanvas.xaml.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
private void ColorShadingCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point p = e.GetPosition(_colorShadingCanvas);
UpdateColorShadeSelectorPositionAndCalculateColor(p, true);
_colorShadingCanvas.CaptureMouse();
//Prevent from closing ColorCanvas after mouseDown in ListView
e.Handled = true;
}
19
Source : ColorCanvas.xaml.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
private void ColorShadingCanvas_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point p = e.GetPosition(_colorShadingCanvas);
UpdateColorShadeSelectorPositionAndCalculateColor(p, true);
Mouse.Synchronize();
}
}
19
Source : LineNumberMargin.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
SimpleSegment GetTextLineSegment(MouseEventArgs e)
{
Point pos = e.GetPosition(TextView);
pos.X = 0;
pos.Y = pos.Y.CoerceValue(0, TextView.ActualHeight);
pos.Y += TextView.VerticalOffset;
VisualLine vl = TextView.GetVisualLineFromVisualTop(pos.Y);
if (vl == null)
return SimpleSegment.Invalid;
TextLine tl = vl.GetTextLineByVisualYPosition(pos.Y);
int visualStartColumn = vl.GetTextLineVisualStartColumn(tl);
int visualEndColumn = visualStartColumn + tl.Length;
int relStart = vl.FirstDoreplacedentLine.Offset;
int startOffset = vl.GetRelativeOffset(visualStartColumn) + relStart;
int endOffset = vl.GetRelativeOffset(visualEndColumn) + relStart;
if (endOffset == vl.LastDoreplacedentLine.Offset + vl.LastDoreplacedentLine.Length)
endOffset += vl.LastDoreplacedentLine.DelimiterLength;
return new SimpleSegment(startOffset, endOffset - startOffset);
}
19
Source : SelectionMouseHandler.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
void textArea_QueryCursor(object sender, QueryCursorEventArgs e)
{
if (!e.Handled) {
if (mode != SelectionMode.None || !enableTextDragDrop) {
e.Cursor = Cursors.IBeam;
e.Handled = true;
} else if (textArea.TextView.VisualLinesValid) {
// Only query the cursor if the visual lines are valid.
// If they are invalid, the cursor will get re-queried when the visual lines
// get refreshed.
Point p = e.GetPosition(textArea.TextView);
if (p.X >= 0 && p.Y >= 0 && p.X <= textArea.TextView.ActualWidth && p.Y <= textArea.TextView.ActualHeight) {
int visualColumn;
bool isAtEndOfLine;
int offset = GetOffsetFromMousePosition(e, out visualColumn, out isAtEndOfLine);
if (textArea.Selection.Contains(offset))
e.Cursor = Cursors.Arrow;
else
e.Cursor = Cursors.IBeam;
e.Handled = true;
}
}
}
}
19
Source : SelectionMouseHandler.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
void textArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
mode = SelectionMode.None;
if (!e.Handled && e.ChangedButton == MouseButton.Left) {
ModifierKeys modifiers = Keyboard.Modifiers;
bool shift = (modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;
if (enableTextDragDrop && e.ClickCount == 1 && !shift) {
int visualColumn;
bool isAtEndOfLine;
int offset = GetOffsetFromMousePosition(e, out visualColumn, out isAtEndOfLine);
if (textArea.Selection.Contains(offset)) {
if (textArea.CaptureMouse()) {
mode = SelectionMode.PossibleDragStart;
possibleDragStartMousePos = e.GetPosition(textArea);
}
e.Handled = true;
return;
}
}
var oldPosition = textArea.Caret.Position;
SetCaretOffsetToMousePosition(e);
if (!shift) {
textArea.ClearSelection();
}
if (textArea.CaptureMouse()) {
if ((modifiers & ModifierKeys.Alt) == ModifierKeys.Alt && textArea.Options.EnableRectangularSelection) {
mode = SelectionMode.Rectangular;
if (shift && textArea.Selection is RectangleSelection) {
textArea.Selection = textArea.Selection.StartSelectionOrSetEndpoint(oldPosition, textArea.Caret.Position);
}
} else if (e.ClickCount == 1 && ((modifiers & ModifierKeys.Control) == 0)) {
mode = SelectionMode.Normal;
if (shift && !(textArea.Selection is RectangleSelection)) {
textArea.Selection = textArea.Selection.StartSelectionOrSetEndpoint(oldPosition, textArea.Caret.Position);
}
} else {
SimpleSegment startWord;
if (e.ClickCount == 3) {
mode = SelectionMode.WholeLine;
startWord = GetLineAtMousePosition(e);
} else {
mode = SelectionMode.WholeWord;
startWord = GetWordAtMousePosition(e);
}
if (startWord == SimpleSegment.Invalid) {
mode = SelectionMode.None;
textArea.ReleaseMouseCapture();
return;
}
if (shift && !textArea.Selection.IsEmpty) {
if (startWord.Offset < textArea.Selection.SurroundingSegment.Offset) {
textArea.Selection = textArea.Selection.SetEndpoint(new TextViewPosition(textArea.Doreplacedent.GetLocation(startWord.Offset)));
} else if (startWord.EndOffset > textArea.Selection.SurroundingSegment.EndOffset) {
textArea.Selection = textArea.Selection.SetEndpoint(new TextViewPosition(textArea.Doreplacedent.GetLocation(startWord.EndOffset)));
}
this.startWord = new AnchorSegment(textArea.Doreplacedent, textArea.Selection.SurroundingSegment);
} else {
textArea.Selection = Selection.Create(textArea, startWord.Offset, startWord.EndOffset);
this.startWord = new AnchorSegment(textArea.Doreplacedent, startWord.Offset, startWord.Length);
}
}
}
}
e.Handled = true;
}
19
Source : SelectionMouseHandler.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
SimpleSegment GetWordAtMousePosition(MouseEventArgs e)
{
TextView textView = textArea.TextView;
if (textView == null) return SimpleSegment.Invalid;
Point pos = e.GetPosition(textView);
if (pos.Y < 0)
pos.Y = 0;
if (pos.Y > textView.ActualHeight)
pos.Y = textView.ActualHeight;
pos += textView.ScrollOffset;
VisualLine line = textView.GetVisualLineFromVisualTop(pos.Y);
if (line != null) {
int visualColumn = line.GetVisualColumn(pos, textArea.Selection.EnableVirtualSpace);
int wordStartVC = line.GetNextCaretPosition(visualColumn + 1, LogicalDirection.Backward, CaretPositioningMode.WordStartOrSymbol, textArea.Selection.EnableVirtualSpace);
if (wordStartVC == -1)
wordStartVC = 0;
int wordEndVC = line.GetNextCaretPosition(wordStartVC, LogicalDirection.Forward, CaretPositioningMode.WordBorderOrSymbol, textArea.Selection.EnableVirtualSpace);
if (wordEndVC == -1)
wordEndVC = line.VisualLength;
int relOffset = line.FirstDoreplacedentLine.Offset;
int wordStartOffset = line.GetRelativeOffset(wordStartVC) + relOffset;
int wordEndOffset = line.GetRelativeOffset(wordEndVC) + relOffset;
return new SimpleSegment(wordStartOffset, wordEndOffset - wordStartOffset);
} else {
return SimpleSegment.Invalid;
}
}
19
Source : SelectionMouseHandler.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
SimpleSegment GetLineAtMousePosition(MouseEventArgs e)
{
TextView textView = textArea.TextView;
if (textView == null) return SimpleSegment.Invalid;
Point pos = e.GetPosition(textView);
if (pos.Y < 0)
pos.Y = 0;
if (pos.Y > textView.ActualHeight)
pos.Y = textView.ActualHeight;
pos += textView.ScrollOffset;
VisualLine line = textView.GetVisualLineFromVisualTop(pos.Y);
if (line != null) {
return new SimpleSegment(line.StartOffset, line.LastDoreplacedentLine.EndOffset - line.StartOffset);
} else {
return SimpleSegment.Invalid;
}
}
19
Source : SelectionMouseHandler.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
int GetOffsetFromMousePosition(MouseEventArgs e, out int visualColumn, out bool isAtEndOfLine)
{
return GetOffsetFromMousePosition(e.GetPosition(textArea.TextView), out visualColumn, out isAtEndOfLine);
}
19
Source : SelectionMouseHandler.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
void textArea_MouseMove(object sender, MouseEventArgs e)
{
if (e.Handled)
return;
if (mode == SelectionMode.Normal || mode == SelectionMode.WholeWord || mode == SelectionMode.WholeLine || mode == SelectionMode.Rectangular) {
e.Handled = true;
if (textArea.TextView.VisualLinesValid) {
// If the visual lines are not valid, don't extend the selection.
// Extending the selection forces a VisualLine refresh, and it is sufficient
// to do that on MouseUp, we don't have to do it every MouseMove.
ExtendSelectionToMouse(e);
}
} else if (mode == SelectionMode.PossibleDragStart) {
e.Handled = true;
Vector mouseMovement = e.GetPosition(textArea) - possibleDragStartMousePos;
if (Math.Abs(mouseMovement.X) > SystemParameters.MinimumHorizontalDragDistance
|| Math.Abs(mouseMovement.Y) > SystemParameters.MinimumVerticalDragDistance)
{
StartDrag();
}
}
}
19
Source : SelectionMouseHandler.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
void SetCaretOffsetToMousePosition(MouseEventArgs e, ISegment allowedSegment)
{
int visualColumn;
bool isAtEndOfLine;
int offset;
if (mode == SelectionMode.Rectangular) {
offset = GetOffsetFromMousePositionFirstTextLineOnly(e.GetPosition(textArea.TextView), out visualColumn);
isAtEndOfLine = true;
} else {
offset = GetOffsetFromMousePosition(e, out visualColumn, out isAtEndOfLine);
}
if (allowedSegment != null) {
offset = offset.CoerceValue(allowedSegment.Offset, allowedSegment.EndOffset);
}
if (offset >= 0) {
textArea.Caret.Position = new TextViewPosition(textArea.Doreplacedent.GetLocation(offset), visualColumn) { IsAtEndOfLine = isAtEndOfLine };
textArea.Caret.DesiredXPos = double.NaN;
}
}
19
Source : MouseHoverLogic.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
void MouseHoverLogicMouseMove(object sender, MouseEventArgs e)
{
Vector mouseMovement = mouseHoverStartPoint - e.GetPosition(this.target);
if (Math.Abs(mouseMovement.X) > SystemParameters.MouseHoverWidth
|| Math.Abs(mouseMovement.Y) > SystemParameters.MouseHoverHeight)
{
StartHovering(e);
}
// do not set e.Handled - allow others to also handle MouseMove
}
19
Source : MouseHoverLogic.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
void StartHovering(MouseEventArgs e)
{
StopHovering();
mouseHoverStartPoint = e.GetPosition(this.target);
mouseHoverLastEventArgs = e;
mouseHoverTimer = new DispatcherTimer(SystemParameters.MouseHoverTime, DispatcherPriority.Background, OnMouseHoverTimerElapsed, this.target.Dispatcher);
mouseHoverTimer.Start();
}
19
Source : DragAndDropProps.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
private static void Fe_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
SetDragStartPoint((DependencyObject)sender, e.GetPosition((IInputElement)sender));
}
19
Source : RibbonGallery.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
base.OnPreviewMouseDown(e);
this.mStartPoint = e.GetPosition(null);
// TODO: This works, but it's a bit too fragile...
this.SelectedItem = e.Source;
}
19
Source : CanvasView.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
if (this.mPart_ItemsControl == null)
return;
if (this.mGotMouseDown == LeftMouseButton.IsClicked ||
(CanvasViewModel.CanvasViewMouseHandler == null && e.ChangedButton != MouseButton.Left))
{
base.OnPreviewMouseDown(e);
return;
}
this.BeginMouseOperation();
this.mDragStart = e.GetPosition(this.mPart_ItemsControl);
this.mDragShape = this.GetShapeAt(this.mDragStart);
e.Handled = (CanvasViewModel.CanvasViewMouseHandler != null) || (CanvasViewModel.SelectedItem.Count > 1);
}
19
Source : CanvasView.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
protected override void OnPreviewMouseMove(MouseEventArgs e)
{
if (this.mPart_ItemsControl == null)
return;
if (this.mGotMouseDown == LeftMouseButton.IsNotClicked)
return;
Point position = e.GetPosition(this.mPart_ItemsControl);
Vector dragDelta = position - this.mDragStart;
if (this.IsMouseCaptured == false)
{
if (e.LeftButton != MouseButtonState.Pressed)
return; // We're not dragging anything.
// This CanvasView is not responsible for the dragging.
if (this.IsMouseCaptureWithin == true)
return;
if (Math.Abs(dragDelta.X) < SystemParameters.MinimumHorizontalDragDistance &&
Math.Abs(dragDelta.Y) < SystemParameters.MinimumVerticalDragDistance)
return;
this.mCurrentMouseHandler.OnShapeDragBegin(position, this.mDragShape);
this.CaptureMouse();
}
this.mCurrentMouseHandler.OnShapeDragUpdate(position, dragDelta);
// The new "drag start" is the current mouse position.
this.mDragStart = position;
}
19
Source : CanvasView.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
if (this.mPart_ItemsControl == null)
return;
if (this.mGotMouseDown == LeftMouseButton.IsNotClicked)
return;
// This try block ends with an EndMouseOperation which chnages/checks the datamodel state
// be careful when editing this part !!!
try
{
if (this.mPart_ItemsControl != null)
{
Point position = e.GetPosition(this.mPart_ItemsControl);
if (this.IsMouseCaptured == false)
{
this.mCurrentMouseHandler.OnShapeClick(this.mDragShape);
return;
}
this.ReleaseMouseCapture();
this.mCurrentMouseHandler.OnShapeDragUpdate(position, position - this.mDragStart);
this.mCurrentMouseHandler.OnShapeDragEnd(position, this.GetShapeAt(position));
}
}
finally
{
this.EndMouseOperation();
}
/* HACK: Work-around for bug 4
_CanvasViewModel.DoreplacedentViewModel.dm_DoreplacedentDataModel.Undo();
_CanvasViewModel.DoreplacedentViewModel.dm_DoreplacedentDataModel.Redo();
* */
}
19
Source : CanvasView.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (e.Source == this)
{
if (this.IsFocused == false)
this.Focus();
}
else
{
// in case that this click is the start for a drag operation we cache the start point
if (this.mCurrentMouseHandler != this && this.mCurrentMouseHandler != null)
{
Point position = e.GetPosition(this);
this.mCurrentMouseHandler.OnShapeDragBegin(position, null);
}
}
e.Handled = true;
}
19
Source : SimpleMetroWindow.xaml.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
internal static void DoWindowreplacedleThumbSystemMenuOnMouseRightButtonUp(SimpleMetroWindow window, MouseButtonEventArgs e)
{
if (window.ShowSystemMenuOnRightClick)
{
// show menu only if mouse pos is on replacedle bar or if we have a window with none style and no replacedle bar
var mousePos = e.GetPosition(window);
////if ((mousePos.Y <= window.replacedlebarHeight && window.replacedlebarHeight > 0) || (window.UseNoneWindowStyle && window.replacedlebarHeight <= 0))
////{
ShowSystemMenuPhysicalCoordinates(window, window.PointToScreen(mousePos));
////}
}
}
19
Source : AbstractBaseUpDown.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
private Point GetPositionFromThis(MouseEventArgs e)
{
return this.PointToScreen(e.GetPosition(this));
}
19
Source : MetroWindow.xaml.cs
with MIT License
from Dirkster99
with MIT License
from Dirkster99
internal static void DoWindowreplacedleThumbSystemMenuOnMouseRightButtonUp(MetroWindow window, MouseButtonEventArgs e)
{
if (window.ShowSystemMenuOnRightClick)
{
// show menu only if mouse pos is on replacedle bar or if we have a window with none style and no replacedle bar
var mousePos = e.GetPosition(window);
////if ((mousePos.Y <= window.replacedlebarHeight && window.replacedlebarHeight > 0) || (window.UseNoneWindowStyle && window.replacedlebarHeight <= 0))
////{
ShowSystemMenuPhysicalCoordinates(window, window.PointToScreen(mousePos));
////}
}
}
19
Source : CropService.cs
with MIT License
from dmitryshelamov
with MIT License
from dmitryshelamov
private void AdornerOnMouseMove(object sender, MouseEventArgs e)
{
var point = e.GetPosition(_canvas);
var newPosition = _currentToolState.OnMouseMove(point);
if (newPosition.HasValue)
{
_cropTool.Redraw(newPosition.Value.Left, newPosition.Value.Top, newPosition.Value.Width, newPosition.Value.Height);
}
}
19
Source : CropService.cs
with MIT License
from dmitryshelamov
with MIT License
from dmitryshelamov
private void AdornerOnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
_canvas.CaptureMouse();
var point = e.GetPosition(_canvas);
var touch = GetTouchPoint(point);
if (touch == TouchPoint.OutsideRectangle)
{
_currentToolState = _createState;
}
else if (touch == TouchPoint.InsideRectangle)
{
_currentToolState = _dragState;
}
_currentToolState.OnMouseDown(point);
}
19
Source : SharpTreeViewItem.cs
with MIT License
from dolkensp
with MIT License
from dolkensp
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
wreplacedelected = IsSelected;
if (!IsSelected) {
base.OnMouseLeftButtonDown(e);
}
if (Mouse.LeftButton == MouseButtonState.Pressed) {
startPoint = e.GetPosition(null);
CaptureMouse();
if (e.ClickCount == 2) {
wasDoubleClick = true;
}
}
}
19
Source : SharpTreeViewItem.cs
with MIT License
from dolkensp
with MIT License
from dolkensp
protected override void OnMouseMove(MouseEventArgs e)
{
if (IsMouseCaptured) {
var currentPoint = e.GetPosition(null);
if (Math.Abs(currentPoint.X - startPoint.X) >= SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(currentPoint.Y - startPoint.Y) >= SystemParameters.MinimumVerticalDragDistance) {
var selection = ParentTreeView.GetTopLevelSelection().ToArray();
if (Node.CanDrag(selection)) {
Node.StartDrag(this, selection);
}
}
}
}
19
Source : WPFDrawableControl.cs
with MIT License
from dotnet
with MIT License
from dotnet
private PointF[] GetViewPoints(MouseButtonEventArgs evt)
{
var point = evt.GetPosition(this);
return new PointF[] { new PointF((float)point.X, (float)point.Y) };
}
19
Source : WPFDrawableControl.cs
with MIT License
from dotnet
with MIT License
from dotnet
private PointF[] GetViewPoints(MouseEventArgs evt)
{
var point = evt.GetPosition(this);
return new PointF[] { new PointF((float)point.X, (float)point.Y) };
}
19
Source : ClinicalTrial.xaml.cs
with MIT License
from dotnet
with MIT License
from dotnet
private void Rectangle_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed) return;
FrameworkElement el = (FrameworkElement)sender;
if (el != startEl) return;
Point pos = e.GetPosition(el);
pos = OnClickOrDrag(el, pos);
e.Handled = true;
}
19
Source : ClassifierView.xaml.cs
with MIT License
from dotnet
with MIT License
from dotnet
private void Rectangle_MouseMove(object sender, MouseEventArgs e)
{
if (dragPoint.X < 0) return;
Rectangle r = (Rectangle)sender;
Point pt = e.GetPosition(this);
Item item = (Item)r.DataContext;
FrameworkElement dobj = (FrameworkElement)itemsControl.ItemContainerGenerator.ContainerFromItem(item);
double x = (double)dobj.GetValue(Canvas.LeftProperty);
double y = (double)dobj.GetValue(Canvas.TopProperty);
dobj.BeginAnimation(Canvas.LeftProperty, null);
dobj.BeginAnimation(Canvas.TopProperty, null);
double newx = pt.X - dragPoint.X + x;
double newy = pt.Y - dragPoint.Y + y;
dobj.SetValue(Canvas.LeftProperty, newx);
dobj.SetValue(Canvas.TopProperty, newy);
dragPoint = pt;
}
19
Source : ClinicalTrial.xaml.cs
with MIT License
from dotnet
with MIT License
from dotnet
private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
FrameworkElement el = (FrameworkElement)sender;
startEl = el;
Point pos = e.GetPosition(el);
// Size of a child element
pos = OnClickOrDrag(el, pos);
e.Handled = true;
}
19
Source : ClassifierView.xaml.cs
with MIT License
from dotnet
with MIT License
from dotnet
private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Rectangle r = (Rectangle)sender;
dragPoint = e.GetPosition(this);
r.CaptureMouse();
}
19
Source : SaturationBrightnessPicker.xaml.cs
with MIT License
from dotnet
with MIT License
from dotnet
protected override void OnMouseUp(MouseButtonEventArgs e)
{
base.OnMouseUp(e);
Mouse.Capture(null);
var pos = e.GetPosition(this).Clamp(this);
Update(pos);
}
19
Source : HuePicker.xaml.cs
with MIT License
from dotnet
with MIT License
from dotnet
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.LeftButton != MouseButtonState.Pressed)
{
return;
}
Mouse.Capture(this);
Update(e.GetPosition(this).Clamp(this));
}
19
Source : HuePicker.xaml.cs
with MIT License
from dotnet
with MIT License
from dotnet
protected override void OnMouseUp(MouseButtonEventArgs e)
{
base.OnMouseUp(e);
Mouse.Capture(null);
Update(e.GetPosition(this).Clamp(this));
}
19
Source : SaturationBrightnessPicker.xaml.cs
with MIT License
from dotnet
with MIT License
from dotnet
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.LeftButton != MouseButtonState.Pressed)
{
return;
}
Mouse.Capture(this);
var pos = e.GetPosition(this).Clamp(this);
Update(pos);
}
19
Source : SelectionEditor.cs
with MIT License
from dotnet
with MIT License
from dotnet
private void OnAdornerMouseButtonDownEvent(object sender, MouseButtonEventArgs args)
{
// If the ButtonDown is raised by RightMouse, we should just bail out.
if ( (args.StylusDevice == null && args.LeftButton != MouseButtonState.Pressed) )
{
return;
}
Point pointOnSelectionAdorner = args.GetPosition(InkCanvas.SelectionAdorner);
InkCanvreplacedelectionHitResult hitResult = InkCanvreplacedelectionHitResult.None;
// Check if we should start resizing/moving
hitResult = HitTestOnSelectionAdorner(pointOnSelectionAdorner);
if ( hitResult != InkCanvreplacedelectionHitResult.None )
{
// We always use MouseDevice for the selection editing.
EditingCoordinator.ActivateDynamicBehavior(EditingCoordinator.SelectionEditingBehavior, args.Device);
}
else
{
//
//push selection and we're done
//
// If the current captured device is Stylus, we should activate the LreplacedoSelectionBehavior with
// the Stylus. Otherwise, use mouse.
EditingCoordinator.ActivateDynamicBehavior(EditingCoordinator.LreplacedoSelectionBehavior,
args.StylusDevice != null ? args.StylusDevice : args.Device);
}
}
19
Source : SelectionEditor.cs
with MIT License
from dotnet
with MIT License
from dotnet
private void OnAdornerMouseMoveEvent(object sender, MouseEventArgs args)
{
Point pointOnSelectionAdorner = args.GetPosition(InkCanvas.SelectionAdorner);
UpdateSelectionCursor(pointOnSelectionAdorner);
}
19
Source : SelectionEditingBehavior.cs
with MIT License
from dotnet
with MIT License
from dotnet
private void OnMouseMove(object sender, MouseEventArgs args)
{
// Get the current mouse location.
Point curPoint = args.GetPosition(InkCanvas.SelectionAdorner);
// Check if we have a mouse movement at all.
if ( !DoubleUtil.AreClose(curPoint.X, _previousLocation.X)
|| !DoubleUtil.AreClose(curPoint.Y, _previousLocation.Y) )
{
// We won't start the move until we really see a movement.
if ( !_actionStarted )
{
_actionStarted = true;
}
// Get the new rectangle
Rect newRect = ChangeFeedbackRectangle(curPoint);
// Update the feedback rubber band and record the current tracking rectangle.
InkCanvas.InkCanvreplacedelection.UpdateFeedbackAdorner(newRect);
_previousRect = newRect;
}
}
19
Source : SelectionEditingBehavior.cs
with MIT License
from dotnet
with MIT License
from dotnet
private void OnMouseUp(object sender, MouseButtonEventArgs args)
{
// We won't start the move until we really see a movement.
if ( _actionStarted )
{
_previousRect = ChangeFeedbackRectangle(args.GetPosition(InkCanvas.SelectionAdorner));
}
Commit(true);
}
19
Source : DataGridColumnHeadersPresenter.cs
with MIT License
from dotnet
with MIT License
from dotnet
internal void OnHeaderMouseLeftButtonDown(MouseButtonEventArgs e)
{
if (ParentDataGrid == null)
{
return;
}
if (_columnHeaderDragIndicator != null)
{
RemoveVisualChild(_columnHeaderDragIndicator);
_columnHeaderDragIndicator = null;
}
if (_columnHeaderDropLocationIndicator != null)
{
RemoveVisualChild(_columnHeaderDropLocationIndicator);
_columnHeaderDropLocationIndicator = null;
}
Point mousePosition = e.GetPosition(this);
DataGridColumnHeader header = FindColumnHeaderByPosition(mousePosition);
if (header != null)
{
DataGridColumn column = header.Column;
if (ParentDataGrid.CreplacederReorderColumns && column.CreplacederReorder)
{
PrepareColumnHeaderDrag(header, e.GetPosition(this), e.GetPosition(header));
}
}
else
{
_isColumnHeaderDragging = false;
_prepareColumnHeaderDragging = false;
_draggingSrcColumnHeader = null;
InvalidateArrange();
}
}
19
Source : DataGridColumnHeadersPresenter.cs
with MIT License
from dotnet
with MIT License
from dotnet
internal void OnHeaderMouseMove(MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
if (_prepareColumnHeaderDragging)
{
_columnHeaderDragCurrentPosition = e.GetPosition(this);
if (!_isColumnHeaderDragging)
{
if (CheckStartColumnHeaderDrag(_columnHeaderDragCurrentPosition, _columnHeaderDragStartPosition))
{
StartColumnHeaderDrag();
}
}
else
{
bool shouldDisplayDragIndicator = IsMousePositionValidForColumnDrag(2.0);
Visibility dragIndicatorVisibility = shouldDisplayDragIndicator ? Visibility.Visible : Visibility.Collapsed;
if (_columnHeaderDragIndicator != null)
{
_columnHeaderDragIndicator.Visibility = dragIndicatorVisibility;
}
if (_columnHeaderDropLocationIndicator != null)
{
_columnHeaderDropLocationIndicator.Visibility = dragIndicatorVisibility;
}
InvalidateArrange();
DragDeltaEventArgs dragDeltaEventArgs = new DragDeltaEventArgs(
_columnHeaderDragCurrentPosition.X - _columnHeaderDragStartPosition.X,
_columnHeaderDragCurrentPosition.Y - _columnHeaderDragStartPosition.Y);
_columnHeaderDragStartPosition = _columnHeaderDragCurrentPosition;
ParentDataGrid.OnColumnHeaderDragDelta(dragDeltaEventArgs);
}
}
}
}
19
Source : Thumb.cs
with MIT License
from dotnet
with MIT License
from dotnet
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
if (!IsDragging)
{
e.Handled = true;
Focus();
CaptureMouse();
SetValue(IsDraggingPropertyKey, true);
_originThumbPoint = e.GetPosition(this);
_previousScreenCoordPosition = _originScreenCoordPosition = SafeSecurityHelper.ClientToScreen(this,_originThumbPoint);
bool exceptionThrown = true;
try
{
RaiseEvent(new DragStartedEventArgs(_originThumbPoint.X, _originThumbPoint.Y));
exceptionThrown = false;
}
finally
{
if (exceptionThrown)
{
CancelDrag();
}
}
}
else
{
// This is weird, Thumb shouldn't get MouseLeftButtonDown event while dragging.
// This may be the case that something ate MouseLeftButtonUp event, so Thumb never had a chance to
// reset IsDragging property
Debug.replacedert(false,"Got MouseLeftButtonDown event while dragging!");
}
base.OnMouseLeftButtonDown(e);
}
19
Source : DataGridCheckBoxColumn.cs
with MIT License
from dotnet
with MIT License
from dotnet
private static bool IsMouseOver(CheckBox checkBox, RoutedEventArgs e)
{
// This element is new, so the IsMouseOver property will not have been updated
// yet, but there is enough information to do a hit-test.
return checkBox.InputHitTest(((MouseButtonEventArgs)e).GetPosition(checkBox)) != null;
}
19
Source : DatePicker.cs
with MIT License
from dotnet
with MIT License
from dotnet
private void PopUp_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Popup popup = sender as Popup;
if (popup != null && !popup.StaysOpen)
{
if (this._dropDownButton != null)
{
if (this._dropDownButton.InputHitTest(e.GetPosition(this._dropDownButton)) != null)
{
// This popup is being closed by a mouse press on the drop down button
// The following mouse release will cause the closed popup to immediately reopen.
// Raise a flag to block reopeneing the popup
this._disablePopupReopen = true;
}
}
}
}
See More Examples