bool IsMouseInBounds() { // Determines if the mouse is over the window. // Normally Mouse.Directly over would tell you but the window is transparent so... int[] position = Win32Mouse.GetMousePosition(); Rect bounds = new Rect(Left, Top, ActualWidth, ActualHeight); return(bounds.Contains(new System.Windows.Point(position[0], position[1]))); }
/// <summary> /// Opens the shell context menu instead of the normal context menu on right click. /// </summary> static void OnContextMenuOpening(object sender, ContextMenuEventArgs e) { Control control = sender as Control; // Attempt to open the explorer context menu for the application. If the file does not exist or // there is some other problem then a context menu (defined in the XAML) with just "Edit Entry" // and "Remove Entry" is opened instead. if (control != null && control.DataContext is ApplicationViewModel) { ApplicationViewModel application = (ApplicationViewModel)control.DataContext; if (File.Exists(application.FilePath)) { ContextMenuWrapper cmw = new ContextMenuWrapper(); cmw.OnQueryMenuItems += (QueryMenuItemsEventHandler) delegate(object s, QueryMenuItemsEventArgs args) { args.ExtraMenuItems = new string[] { "Edit Dock Entry", "Remove Dock Entry", "---" }; args.GrayedItems = new string[] { "delete", "rename", "cut", "copy" }; args.HiddenItems = new string[] { "link" }; args.DefaultItem = 1; }; cmw.OnAfterPopup += (AfterPopupEventHandler) delegate(object s, AfterPopupEventArgs args) { Messenger.Default.Send <ShellContextMenuMessage>(ShellContextMenuMessage.Closed()); }; Messenger.Default.Send <ShellContextMenuMessage>(ShellContextMenuMessage.Opened()); try { FileSystemInfoEx[] files = new[] { FileInfoEx.FromString(application.FilePath) }; int[] position = Win32Mouse.GetMousePosition(); string command = cmw.Popup(files, new System.Drawing.Point(position[0], position[1])); // Handle the click on the 'ExtraMenuItems'. switch (command) { case "Edit Dock Entry": Messenger.Default.Send <ApplicationMessage>(ApplicationMessage.Edit(application)); break; case "Remove Dock Entry": Messenger.Default.Send <ApplicationMessage>(ApplicationMessage.Remove(application)); break; } e.Handled = true; // Don't open the normal context menu. } catch (Exception ex) { Debug.Print("Problem displaying shell context menu: {0}", ex); } } } }
void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { FrameworkElement element = sender as FrameworkElement; if (element != null) { int[] position = Win32Mouse.GetMousePosition(); _start = new Point(position[0], position[1]); _dragged = element; } }
bool OverScreenEdge() { int offset = 5; int[] mousePosition = Win32Mouse.GetMousePosition(); // Make sure the mouse point is inside the screen bounds. if (!ActiveScreen.WorkingArea.Contains(mousePosition[0], mousePosition[1])) { return(false); } switch (Docked.Selected) { case DockEdge.Left: if (mousePosition[0] <= ActiveScreen.WorkingArea.Left + offset) { // Close enough to the edge. return(true); } break; case DockEdge.Right: if (mousePosition[0] >= ActiveScreen.WorkingArea.Right - offset) { // Close enough to the edge. return(true); } break; case DockEdge.Top: if (mousePosition[1] <= ActiveScreen.WorkingArea.Top + offset) { // Close enough to the edge. return(true); } break; case DockEdge.Bottom: if (mousePosition[1] >= ActiveScreen.WorkingArea.Bottom - offset) { // Close enough to the edge. return(true); } break; } return(false); }
void OnPreviewMouseMove(object sender, MouseEventArgs e) { FrameworkElement element = sender as FrameworkElement; if (element != null && _dragged != null) { int[] position = Win32Mouse.GetMousePosition(); Point currentPosition = new Point(position[0], position[1]); Vector diff = _start - currentPosition; if (e.LeftButton == MouseButtonState.Pressed && Math.Abs(diff.X) > (SystemParameters.MinimumHorizontalDragDistance) && Math.Abs(diff.Y) > (SystemParameters.MinimumVerticalDragDistance)) { DragDropEffects effects = DragDrop.DoDragDrop(element, _dragged.DataContext, DragDropEffects.Move); _dragged = null; e.Handled = true; } } }