void GenericMouseEventHandler(RoutedEvent previewevent, RoutedEvent finalevent, MouseEventArgs e, MouseEventArgs clone) { if (e.StylusDevice != null) { e.Handled = true; return; } if (_rerouting) { return; } if (mousecapture != null) { IInputElement target = mousecapture; _rerouting = true; clone.RoutedEvent = previewevent; clone.Source = e.Source; target.RaiseEvent(clone); clone.RoutedEvent = finalevent; target.RaiseEvent(clone); e.Handled = true; _rerouting = false; } }
void GenericMouseButtonEventHandler(RoutedEvent previewevent, RoutedEvent finalevent, bool isdownnotup, MouseButtonEventArgs e, MouseButtonEventArgs clone) { if (e.StylusDevice != null) { e.Handled = true; return; } if (_rerouting) { return; } if (mousecapture != null) { IInputElement target = mousecapture; _rerouting = true; clone.RoutedEvent = previewevent; clone.Source = e.Source; target.RaiseEvent(clone); clone.RoutedEvent = (isdownnotup ? UIElement.PreviewMouseDownEvent : UIElement.PreviewMouseUpEvent); target.RaiseEvent(clone); clone.RoutedEvent = finalevent; target.RaiseEvent(clone); clone.RoutedEvent = (isdownnotup ? UIElement.MouseDownEvent : UIElement.MouseUpEvent); target.RaiseEvent(clone); e.Handled = true; _rerouting = false; } }
private void ProcessRawEvent(RawKeyEventArgs e) { IInputElement element = this.FocusedElement; if (element != null) { switch (e.Type) { case RawKeyEventType.KeyDown: KeyEventArgs ev = new KeyEventArgs { RoutedEvent = InputElement.PreviewKeyDownEvent, Device = this, Key = e.Key, Text = e.Text, Source = element, OriginalSource = element, }; element.RaiseEvent(ev);; ev.RoutedEvent = InputElement.KeyDownEvent; element.RaiseEvent(ev);; break; } } }
virtual protected void GenericStylusEventHandler(RoutedEvent previewevent, RoutedEvent finalevent, StylusEventArgs e, StylusEventArgs clone) { if (Mouse.Captured != null) { e.Handled = true; return; } if (_rerouting) { return; } IInputElement target = capturemap.ContainsKey(e.StylusDevice.Id) ? capturemap[e.StylusDevice.Id] : (IInputElement)e.OriginalSource; _rerouting = true; clone.RoutedEvent = previewevent; clone.Source = e.Source; UnmarkStylusListeners(e.StylusDevice.Id); target.RaiseEvent(clone); RaiseStylusListener(clone); clone.RoutedEvent = finalevent; target.RaiseEvent(clone); RaiseStylusListener(clone); _rerouting = false; e.Handled = true; }
virtual protected void GenericMouseEventHandler( RoutedEvent previewevent, RoutedEvent finalevent, MouseEventArgs e, MouseEventArgs clone) { if (e.StylusDevice != null) { e.Handled = true; return; } if (_rerouting) { return; } IInputElement target = (mousecapture == null) ? (IInputElement)e.OriginalSource : mousecapture; _rerouting = true; clone.RoutedEvent = previewevent; clone.Source = e.Source; UnmarkMouseListeners(); target.RaiseEvent(clone); RaiseMouseListener(clone); clone.RoutedEvent = finalevent; RaiseMouseListener(clone); target.RaiseEvent(clone); _rerouting = false; e.Handled = true; }
private void OnPreviewMouseWheel(IInputElement originalSource, MouseWheelInputEventArgs ie) { // Update wheel motion info var info = ie.Wheel.PreTransmit(ie.Timestamp, ie.Delta); // 1. Tunneling event // Clients and behaviors use this tunneling event to update the wheel transfer // case by dynamically creating / retrieving motion shafts. ie.RoutedEvent = PreviewMouseWheelInputEvent; originalSource.RaiseEvent(ie); // In cooperation with clients and behaviors, if inputEventArgs.Handled is set to true, // the controller lets the underlying mouse wheel tunneling event continue its route. if (ie.Handled) { return; } // Fill motion reservoir ie.Wheel.Transmit(info, ie.Delta, null); // 2. Bubbling event // Clients consume the motion here ie.RoutedEvent = MouseWheelInputEvent; originalSource.RaiseEvent(ie); // 3. Remaining motion is processed here ie.EndCommand(); }
protected void DragCardCompleted() { // Release the card and its group foreach (Card c in DraggedCards) { c.ReleaseControl(); } Card.Group.ReleaseControl(); // Remove the visual feedback var mwc = _mainWin.Content as Visual; if (mwc != null) { AdornerLayer layer = AdornerLayer.GetAdornerLayer(mwc); foreach (CardDragAdorner overlay in OverlayElements) { layer.Remove(overlay); overlay.Dispose(); } } OverlayElements.Clear(); // Raise CardOutEvent if (_lastDragTarget != null) { _lastDragTarget.RaiseEvent(new CardsEventArgs(Card, DraggedCards, CardOutEvent, this)); _lastDragTarget = null; } // Raise CardDroppedEvent IInputElement res = Mouse.DirectlyOver; if (res != null) { var args = new CardsEventArgs(Card, DraggedCards, CardDroppedEvent, this) { MouseOffset = _mouseOffset, FaceUp = !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) }; res.RaiseEvent(args); } // Restore full opacity // FIX (jods): if the cards have been moved to another group, groupCtrl is null. // But in this case nothing has to be done opacity-wise since // the CardControls have been unloaded. GroupControl groupCtrl = GroupControl; if (groupCtrl != null) { foreach (CardControl cardCtrl in Selection.GetCardControls(groupCtrl, this)) { cardCtrl.Opacity = 1; } } DraggedCards.Clear(); }
public static bool RaiseEvents(this IInputElement element, RoutedEventArgs previewEventArgs, RoutedEventArgs eventArgs) { element.RaiseEvent(previewEventArgs); eventArgs.Handled = previewEventArgs.Handled; element.RaiseEvent(eventArgs); return(eventArgs.Handled); }
private void OnKeyTipExactMatch(DependencyObject exactMatchElement) { if (!((bool)(exactMatchElement.GetValue(UIElement.IsEnabledProperty)))) { Menu.MenuRibbon.Beep(); _prefixText = string.Empty; return; } HideCurrentShowingKeyTips(); _prefixText = string.Empty; // KeyTips might have been dismissed by one of the event handlers // hence check again. if (State == KeyTipState.None) { return; } var oldFocus = Keyboard.FocusedElement; var args = new KeyTipAccessedEventArgs(); args.RoutedEvent = PreviewKeyTipAccessedEvent; IInputElement inputElement = exactMatchElement as IInputElement; if (inputElement != null) { inputElement.RaiseEvent(args); args.RoutedEvent = KeyTipAccessedEvent; inputElement.RaiseEvent(args); } object newFocus = Keyboard.FocusedElement; DependencyObject newScope = args.TargetKeyTipScope; if (newScope != null && !KeyTipService.GetIsKeyTipScope(newScope) && newScope != globalScope) { throw new InvalidOperationException(); } if (newScope == null && KeyTipService.GetIsKeyTipScope(exactMatchElement)) { newScope = exactMatchElement; } if (newScope != null) { // Show KeyTips for new scope in a dispatcher operation. Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => PushKeyTipsScope(newScope, true)), DispatcherPriority.Loaded); } else { LeaveKeyTipMode(oldFocus == newFocus /*restoreFocus*/); } }
private bool RaiseContextMenuOpeningEvent(IInputElement source, double x, double y, bool userInitiated) { ContextMenuEventArgs contextMenuEventArgs = new ContextMenuEventArgs(source, true, x, y); DependencyObject dependencyObject = source as DependencyObject; if (userInitiated && dependencyObject != null) { if (InputElement.IsUIElement(dependencyObject)) { ((UIElement)dependencyObject).RaiseEvent(contextMenuEventArgs, userInitiated); } else if (InputElement.IsContentElement(dependencyObject)) { ((ContentElement)dependencyObject).RaiseEvent(contextMenuEventArgs, userInitiated); } else if (InputElement.IsUIElement3D(dependencyObject)) { ((UIElement3D)dependencyObject).RaiseEvent(contextMenuEventArgs, userInitiated); } else { source.RaiseEvent(contextMenuEventArgs); } } else { source.RaiseEvent(contextMenuEventArgs); } if (contextMenuEventArgs.Handled) { this.RaiseToolTipClosingEvent(true); return(true); } DependencyObject targetElement = contextMenuEventArgs.TargetElement; if (targetElement != null && ContextMenuService.ContextMenuIsEnabled(targetElement)) { object contextMenu = ContextMenuService.GetContextMenu(targetElement); ContextMenu contextMenu2 = contextMenu as ContextMenu; contextMenu2.SetValue(PopupControlService.OwnerProperty, targetElement); contextMenu2.Closed += this.OnContextMenuClosed; if (x == -1.0 && y == -1.0) { contextMenu2.Placement = PlacementMode.Center; } else { contextMenu2.Placement = PlacementMode.MousePoint; } this.RaiseToolTipClosingEvent(true); contextMenu2.SetCurrentValueInternal(ContextMenu.IsOpenProperty, BooleanBoxes.TrueBox); return(true); } return(false); }
/// <summary> /// Raises the cursor events. /// </summary> /// <param name="element">The ui element under the cursor.</param> /// <param name="cursorPosition">Cursor position.</param> public void RaiseCursorEvents(IInputElement element, Point cursorPosition) { element.RaiseEvent(new HandCursorEventArgs(KinectEvents.HandCursorMoveEvent, cursorPosition)); if (element != _lastElement) { if (_lastElement != null) _lastElement.RaiseEvent(new HandCursorEventArgs(KinectEvents.HandCursorLeaveEvent, cursorPosition)); element.RaiseEvent(new HandCursorEventArgs(KinectEvents.HandCursorEnterEvent, cursorPosition)); } _lastElement = element; }
private static void HandleMouseHorizontalWheel([NotNull] Window handledWindow, IntPtr wParam) { if (handledWindow == null) { throw new ArgumentNullException(nameof(handledWindow)); } int tilt = (short)Win32.HiWord(wParam); if (tilt == 0) { return; } IInputElement element = Mouse.DirectlyOver; if (element == null) { return; } if (!(element is UIElement)) { element = VisualTreeHelpers.FindAncestor <UIElement>(element as DependencyObject); } if (element == null) { return; } // make sure the ancestor is this window if (!ReferenceEquals(VisualTreeHelpers.FindAncestor <Window>((DependencyObject)element), handledWindow)) { return; } var ev = new MouseHorizontalWheelEventArgs(Mouse.PrimaryDevice, Environment.TickCount, tilt) { RoutedEvent = PreviewMouseHorizontalWheelEvent //Source = handledWindow }; // first raise preview element.RaiseEvent(ev); if (ev.Handled) { return; } // then bubble it ev.RoutedEvent = MouseHorizontalWheelEvent; element.RaiseEvent(ev); }
//Levanta los eventos del cursor. public void RaiseCursorEvents(IInputElement element, Point cursorPosition) { element.RaiseEvent(new HandCursorEventArgs(KinectEvents.HandCursorMoveEvent, cursorPosition)); if (element != _lastElement) { if (_lastElement != null) { _lastElement.RaiseEvent(new HandCursorEventArgs(KinectEvents.HandCursorLeaveEvent, cursorPosition)); } element.RaiseEvent(new HandCursorEventArgs(KinectEvents.HandCursorEnterEvent, cursorPosition)); } _lastElement = element; }
private void RightClick(IInputElement element) { element.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Right) { RoutedEvent = Mouse.MouseDownEvent }); element.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Right) { RoutedEvent = Mouse.MouseUpEvent }); DispatcherUtil.DoEvents(); }
// Token: 0x06004286 RID: 17030 RVA: 0x00130CBC File Offset: 0x0012EEBC private void UpdateIsDefaulted(IInputElement focus) { if (!this.IsDefault || focus == null || !base.IsEnabled) { base.SetValue(Button.IsDefaultedPropertyKey, BooleanBoxes.FalseBox); return; } DependencyObject dependencyObject = focus as DependencyObject; object value = BooleanBoxes.FalseBox; try { AccessKeyPressedEventArgs accessKeyPressedEventArgs = new AccessKeyPressedEventArgs(); focus.RaiseEvent(accessKeyPressedEventArgs); object scope = accessKeyPressedEventArgs.Scope; accessKeyPressedEventArgs = new AccessKeyPressedEventArgs(); base.RaiseEvent(accessKeyPressedEventArgs); object scope2 = accessKeyPressedEventArgs.Scope; if (scope2 == scope && (dependencyObject == null || !(bool)dependencyObject.GetValue(KeyboardNavigation.AcceptsReturnProperty))) { value = BooleanBoxes.TrueBox; } } finally { base.SetValue(Button.IsDefaultedPropertyKey, value); } }
// Token: 0x060053F2 RID: 21490 RVA: 0x001745F0 File Offset: 0x001727F0 private void OnContextMenuClosed(object source, RoutedEventArgs e) { ContextMenu contextMenu = source as ContextMenu; if (contextMenu != null) { contextMenu.Closed -= this.OnContextMenuClosed; DependencyObject dependencyObject = (DependencyObject)contextMenu.GetValue(PopupControlService.OwnerProperty); if (dependencyObject != null) { contextMenu.ClearValue(PopupControlService.OwnerProperty); UIElement target = PopupControlService.GetTarget(dependencyObject); if (target != null && !PopupControlService.IsPresentationSourceNull(target)) { IInputElement inputElement2; if (!(dependencyObject is ContentElement) && !(dependencyObject is UIElement3D)) { IInputElement inputElement = target; inputElement2 = inputElement; } else { inputElement2 = (IInputElement)dependencyObject; } IInputElement inputElement3 = inputElement2; ContextMenuEventArgs e2 = new ContextMenuEventArgs(inputElement3, false); inputElement3.RaiseEvent(e2); } } } }
/// <summary> /// Finds the nearest element with an enabled tooltip. /// </summary> /// <param name="o"> /// The most "leaf" element to start looking at. /// This element will be replaced with the element that /// contains an active tooltip OR null if the element /// is already in play. /// </param> /// <returns>True if there is an active tooltip in play.</returns> private bool LocateNearestToolTip(ref DependencyObject o) { IInputElement element = o as IInputElement; if (element != null) { FindToolTipEventArgs args = new FindToolTipEventArgs(); element.RaiseEvent(args); if (args.TargetElement != null) { // Open this element's ToolTip o = args.TargetElement; return(true); } else if (args.KeepCurrentActive) { // Keep the current ToolTip active o = null; return(true); } } // Close any existing ToolTips return(false); }
private void OnContextMenuClosed(object source, RoutedEventArgs e) { ContextMenu cm = source as ContextMenu; if (cm != null) { cm.Closed -= OnContextMenuClosed; DependencyObject o = (DependencyObject)cm.GetValue(OwnerProperty); if (o != null) { cm.ClearValue(OwnerProperty); UIElement uie = GetTarget(o); if (uie != null) { if (!IsPresentationSourceNull(uie)) { IInputElement inputElement = (o is ContentElement || o is UIElement3D) ? (IInputElement)o : (IInputElement)uie; ContextMenuEventArgs args = new ContextMenuEventArgs(inputElement, false /*opening */); inputElement.RaiseEvent(args); } } } } }
/// <summary> /// Finds the nearest element with an enabled tooltip. /// </summary> /// <param name="o"> /// The most "leaf" element to start looking at. /// This element will be replaced with the element that /// contains an active tooltip OR null if the element /// is already in play. /// </param> /// <param name="triggerAction"> /// The user action that triggered this search. /// </param> /// <param name="showToolTip"> /// Whether or not the tooltip found should be shown. /// </param> /// <returns>True if a tooltip was located.</returns> private bool LocateNearestToolTip(ref DependencyObject o, ToolTip.ToolTipTrigger triggerAction, ref bool showToolTip) { IInputElement element = o as IInputElement; bool foundToolTip = false; showToolTip = false; if (element != null) { FindToolTipEventArgs args = new FindToolTipEventArgs(triggerAction); element.RaiseEvent(args); foundToolTip = args.Handled; if (args.TargetElement != null) { // Open this element's ToolTip o = args.TargetElement; showToolTip = true; } else if (args.KeepCurrentActive) { // Keep the current ToolTip active o = null; showToolTip = true; } } // Close any existing ToolTips return(foundToolTip); }
public static T RequestInstance <T>(this IInputElement element) { var requestInstance = new RequestInstance(typeof(T)); element.RaiseEvent(requestInstance); return((T)requestInstance.Instance); }
private static void OnDeactivateStoryboardCompleted( IInputElement snackbar, SnackbarMessage message) { var args = new SnackbarMessageEventArgs(DeactivateStoryboardCompletedEvent, message); snackbar.RaiseEvent(args); }
public static void RaiseEvent(this IInputElement source, IEnumerable <RoutedEventArgs> args) { foreach (var e in args) { source.RaiseEvent(e); } }
IntPtr SourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { // Handle WM_GETDLGCODE in order to allow for arrow and tab navigation inside the dialog page. // By returning this code, Windows will pass arrow and tab keys to our HWND instead of handling // them for its own default tab and directional navigation. switch (msg) { case NativeMethods.WM_GETDLGCODE: int dlgCode = NativeMethods.DLGC_WANTARROWS | NativeMethods.DLGC_WANTTAB | NativeMethods.DLGC_WANTCHARS; // Ask the currently-focused element if it wants to handle all keys or not. The DialogKeyPendingEvent // is a routed event starting with the focused control. If any control in the route handles // this message, then we'll add DLGC_WANTALLKEYS to request that this pending message // be delivered to our content instead of the default dialog procedure. IInputElement currentElement = Keyboard.FocusedElement; if (currentElement != null) { DialogKeyEventArgs args = new DialogKeyEventArgs(DialogKeyPendingEvent, KeyInterop.KeyFromVirtualKey(wParam.ToInt32())); currentElement.RaiseEvent(args); if (args.Handled) { dlgCode |= NativeMethods.DLGC_WANTALLKEYS; } } handled = true; return(new IntPtr(dlgCode)); } return(IntPtr.Zero); }
/// <summary> /// 将空气鼠标ActiveHand的“进入”、“离开”事件激发(RaiseEvent) /// </summary> /// <param name="hand"></param> private void HitTestHand(HandPosition hand) { var pt = new Point(hand.X, hand.Y); IInputElement input = this.parentWindow.InputHitTest(pt); if (hand.CurrentElement != input) { var inputObject = input as DependencyObject; var currentObject = hand.CurrentElement as DependencyObject; // If the new input is a child of the current element then don't fire the leave event. // It will be fired later when the current input moves to the parent of the current element. if (hand.CurrentElement != null && Utility.IsElementChild(currentObject, inputObject) == false) { // Raise the HandLeaveEvent on the CurrentElement, which at this point is the previous element the hand was over. hand.CurrentElement.RaiseEvent(new HandInputEventArgs(HandLeaveEvent, hand.CurrentElement, hand)); } // If the current element is the parent of the new input element then don't // raise the entered event as it has already been fired. if (input != null && Utility.IsElementChild(inputObject, currentObject) == false) { input.RaiseEvent(new HandInputEventArgs(HandEnterEvent, input, hand)); } hand.CurrentElement = input; } else if (hand.CurrentElement != null) { hand.CurrentElement.RaiseEvent(new HandInputEventArgs(HandMoveEvent, hand.CurrentElement, hand)); } }
private void OnPinButton(string obj) { TextBox textBox = null; IInputElement target = null; if (AmountNumber == null) { AmountNumber = ""; } { if (!IsFocusedPaymentNote) { IsFocusedPaymentNote = true; target = System.Windows.Input.Keyboard.FocusedElement; textBox = target as TextBox; if (textBox != null) { textBox.SelectionStart = textBox.Text.Length; } } RoutedEvent routedEvent = TextCompositionManager.TextInputEvent; target = System.Windows.Input.Keyboard.FocusedElement; textBox = target as TextBox; target.RaiseEvent(new TextCompositionEventArgs(InputManager.Current.PrimaryKeyboardDevice, new TextComposition(InputManager.Current, target, obj)) { RoutedEvent = routedEvent }); if (textBox != null) { AmountNumber = textBox.Text; } } }
private static void SetFocus(IInputElement senderAsInput) { try { if (senderAsInput is FrameworkElement fe) { fe.BringIntoView(); } Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Input, (Action)(() => { senderAsInput.Focus(); Keyboard.PrimaryDevice.Focus(senderAsInput); })); // //This hack works arround a bug in datepicker -- focusing a datepicker does not focus the textbox if (senderAsInput is DatePicker) { var eventArgs = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource ?? PresentationSource.FromVisual(senderAsInput as Visual), 0, Key.Up); eventArgs.RoutedEvent = DatePicker.KeyDownEvent; Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => senderAsInput.RaiseEvent(eventArgs)), DispatcherPriority.ApplicationIdle); } (senderAsInput as TextBox)?.SelectAll(); } catch (InvalidOperationException) { } }
// // OnMouseTransition: This method is a listener for both the MouseEnter event and // the MouseLeave event on TreeViewItems. It updates the _currentItem, and updates // the IsMouseDirectlyOverItem property on the previous TreeViewItem and the new // TreeViewItem. static void OnMouseTransition(object sender, MouseEventArgs args) { lock (IsMouseDirectlyOverItemProperty) { if (_currentItem != null) { // Tell the item that previously had the mouse that it no longer does. DependencyObject oldItem = _currentItem; _currentItem = null; oldItem.InvalidateProperty(IsMouseDirectlyOverItemProperty); } // Get the element that is currently under the mouse. IInputElement currentPosition = Mouse.DirectlyOver; // See if the mouse is still over something (any element, not just a tree view item). if (currentPosition != null) { // Yes, the mouse is over something. // Raise an event from that point. If a TreeViewItem is anywhere above this point // in the tree, it will receive this event and update _currentItem. RoutedEventArgs newItemArgs = new RoutedEventArgs(UpdateOverItemEvent); currentPosition.RaiseEvent(newItemArgs); } } }
private static void ClearStatusBarAndCachedUri(object sender) { IInputElement inputElement = (IInputElement)sender; inputElement.RaiseEvent(RequestSetStatusBarEventArgs.Clear); Hyperlink.CacheNavigateUri((DependencyObject)sender, null); Hyperlink.s_criticalNavigateUriProtectee.Value = null; }
private static void CheckMouseEvent(TestWindow window, IInputElement button, RoutedEvent routedEvent, bool shouldBeHandled) { var args = new MouseButtonEventArgs(Mouse.PrimaryDevice, (int) DateTime.Now.Ticks, MouseButton.Left); args.RoutedEvent = routedEvent; button.RaiseEvent(args); window.ProcessEvents(); Assert.AreEqual(shouldBeHandled, args.Handled); }
private static void CheckMouseEvent(TestWindow window, IInputElement button, RoutedEvent routedEvent, bool shouldBeHandled) { var args = new MouseButtonEventArgs(Mouse.PrimaryDevice, (int)DateTime.Now.Ticks, MouseButton.Left); args.RoutedEvent = routedEvent; button.RaiseEvent(args); window.ProcessEvents(); Assert.AreEqual(shouldBeHandled, args.Handled); }
private static void HandleMouseHorizontalWheel(IntPtr wParam) { int tilt = -Win32.HiWord(wParam); if (tilt == 0) { return; } IInputElement element = Mouse.DirectlyOver; if (element == null) { return; } if (element is not UIElement) { element = FindAncestor <UIElement>(element as DependencyObject); } if (element == null) { return; } MouseHorizontalWheelEventArgs ev = new MouseHorizontalWheelEventArgs(Mouse.PrimaryDevice, Environment.TickCount, tilt) { RoutedEvent = PreviewMouseHorizontalWheelEvent, //Source = handledWindow }; // first raise preview element.RaiseEvent(ev); if (ev.Handled) { return; } // then bubble it ev.RoutedEvent = MouseHorizontalWheelEvent; element.RaiseEvent(ev); }
private void ProcessRawEvent(RawInputEventArgs e) { IInputElement element = FocusedElement; if (element != null) { var keyInput = e as RawKeyEventArgs; if (keyInput != null) { switch (keyInput.Type) { case RawKeyEventType.KeyDown: case RawKeyEventType.KeyUp: var routedEvent = keyInput.Type == RawKeyEventType.KeyDown ? InputElement.KeyDownEvent : InputElement.KeyUpEvent; KeyEventArgs ev = new KeyEventArgs { RoutedEvent = routedEvent, Device = this, Key = keyInput.Key, Modifiers = keyInput.Modifiers, Source = element, }; element.RaiseEvent(ev); break; } } var text = e as RawTextInputEventArgs; if (text != null) { element.RaiseEvent(new TextInputEventArgs() { Device = this, Text = text.Text, Source = element, RoutedEvent = InputElement.TextInputEvent }); } } }
private bool OnRaiseEndEditEvent(IInputElement uiElement) { if (uiElement == null) return false; var arg = new CellEditRoutedEventArgs(EndEditEvent, this); uiElement.RaiseEvent(arg); if (arg.HasChanged) { //arg.ChangedSet.ForEach(x => DirtyItems.Add(x)); //_isDirty = true; LayerContainer.OnRaiseAfterMouseUpEvent(this); // 刷新控制, 重绘 } return arg.HasChanged; }
private void UpdateIsDefaulted(IInputElement focus) { // If it's not a default button, or nothing is focused, or it's disabled then it's not defaulted. if (!IsDefault || focus == null || !IsEnabled) { SetValue(IsDefaultedPropertyKey, BooleanBoxes.FalseBox); return; } DependencyObject focusDO = focus as DependencyObject; object thisScope, focusScope; // If the focused thing is not in this scope then IsDefaulted = false AccessKeyPressedEventArgs e; object isDefaulted = BooleanBoxes.FalseBox; try { // Step 1: Determine the AccessKey scope from currently focused element e = new AccessKeyPressedEventArgs(); focus.RaiseEvent(e); focusScope = e.Scope; // Step 2: Determine the AccessKey scope from this button e = new AccessKeyPressedEventArgs(); this.RaiseEvent(e); thisScope = e.Scope; // Step 3: Compare scopes if (thisScope == focusScope && (focusDO == null || (bool)focusDO.GetValue(KeyboardNavigation.AcceptsReturnProperty) == false)) { isDefaulted = BooleanBoxes.TrueBox; } } finally { SetValue(IsDefaultedPropertyKey, isDefaulted); } }
private bool RaiseContextMenuOpeningEvent(IInputElement source, double x, double y,bool userInitiated) { // Fire the event ContextMenuEventArgs args = new ContextMenuEventArgs(source, true /* opening */, x, y); DependencyObject sourceDO = source as DependencyObject; if (userInitiated && sourceDO != null) { if (InputElement.IsUIElement(sourceDO)) { ((UIElement)sourceDO).RaiseEvent(args, userInitiated); } else if (InputElement.IsContentElement(sourceDO)) { ((ContentElement)sourceDO).RaiseEvent(args, userInitiated); } else if (InputElement.IsUIElement3D(sourceDO)) { ((UIElement3D)sourceDO).RaiseEvent(args, userInitiated); } else { source.RaiseEvent(args); } } else { source.RaiseEvent(args); } if (!args.Handled) { // No one handled the event, auto show any available ContextMenus // Saved from the bubble up the tree where we looked for a set ContextMenu property DependencyObject o = args.TargetElement; if ((o != null) && ContextMenuService.ContextMenuIsEnabled(o)) { // Retrieve the value object menu = ContextMenuService.GetContextMenu(o); ContextMenu cm = menu as ContextMenu; cm.SetValue(OwnerProperty, o); cm.Closed += new RoutedEventHandler(OnContextMenuClosed); if ((x == -1.0) && (y == -1.0)) { // We infer this to mean that the ContextMenu was opened with the keyboard cm.Placement = PlacementMode.Center; } else { // If there is a CursorLeft and CursorTop, it was opened with the mouse. cm.Placement = PlacementMode.MousePoint; } // Clear any open tooltips RaiseToolTipClosingEvent(true /*reset */); cm.SetCurrentValueInternal(ContextMenu.IsOpenProperty, BooleanBoxes.TrueBox); return true; // A menu was opened } return false; // There was no menu to open } // Clear any open tooltips since someone else opened one RaiseToolTipClosingEvent(true /*reset */); return true; // The event was handled by someone else }
private bool ProcessKeyEventArgs( KeyEventArgs e, IInputElement target ) { bool retval = false; if( target != null ) { //foward the event to the child check box Key realKey; if( ( e.Key == Key.None ) && ( e.SystemKey != Key.None ) ) { realKey = e.SystemKey; } else { realKey = e.Key; } //in XBAP the Keyboard.PrimaryDevice.ActiveSource will throw ,therefore, protect against the throw and suppress the exception //if its the one we expect. try { KeyEventArgs kea = new KeyEventArgs( Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, realKey ); kea.RoutedEvent = e.RoutedEvent; //send the event target.RaiseEvent( kea ); retval = kea.Handled; } catch( SecurityException ex ) { //if the exception is for the UIPermission, then we want to suppress it if( ( ex.PermissionType.FullName == "System.Security.Permissions.UIPermission" ) == false ) { //not correct type, then rethrow the exception throw; } else //this means that we are in XBAP { //we want to handle speciallly the case where the space was pressed (so that checkbox works in XBAP) //condition taken from the System ChecckBox if( ( e.RoutedEvent == Keyboard.KeyDownEvent ) && ( e.Key == Key.Space ) && ( ( Keyboard.Modifiers & ( ModifierKeys.Control | ModifierKeys.Alt ) ) != ModifierKeys.Alt ) && ( this.IsMouseCaptured == false ) ) { if( this.IsChecked.HasValue == true ) { if( this.IsChecked.Value == false ) { this.IsChecked = true; } else if( this.IsThreeState == false ) { this.IsChecked = false; } else { this.IsChecked = null; } } else { this.IsChecked = false; } retval = true; } } } } return retval; }
private static void NavigateToUri(IInputElement sourceElement, Uri targetUri, string targetWindow) { Debug.Assert(targetUri != null); // // This prevents against multi-threaded spoofing attacks. // DependencyObject dObj = (DependencyObject)sourceElement; dObj.VerifyAccess(); // // Spoofing countermeasure makes sure the URI hasn't changed since display in the status bar. // Uri cachedUri = Hyperlink.s_cachedNavigateUri.Value; // ShouldPreventUriSpoofing is checked last in order to avoid incurring a first-chance SecurityException // in common scenarios. if (cachedUri == null || cachedUri.Equals(targetUri) || !ShouldPreventUriSpoofing) { // // We treat FixedPage seperately to maintain backward compatibility // with the original separate FixedPage implementation of this, which // calls the GetLinkUri method. if (!(sourceElement is Hyperlink)) { targetUri = FixedPage.GetLinkUri(sourceElement, targetUri); } RequestNavigateEventArgs navigateArgs = new RequestNavigateEventArgs(targetUri, targetWindow); navigateArgs.Source = sourceElement; sourceElement.RaiseEvent(navigateArgs); if (navigateArgs.Handled) { // // The browser's status bar should be cleared. Otherwise it will still show the // hyperlink address after navigation has completed. // !! We have to do this after the current callstack is unwound in order to keep // the anti-spoofing state valid. A particular attach is to do a bogus call to // DoClick() in a mouse click preview event and then change the NavigateUri. // dObj.Dispatcher.BeginInvoke(DispatcherPriority.Send, new System.Threading.SendOrPostCallback(ClearStatusBarAndCachedUri), sourceElement); } } }
private AccessKeyInformation GetInfoForElement(IInputElement element, string key) { AccessKeyInformation info = new AccessKeyInformation(); if (element != null) { AccessKeyPressedEventArgs args = new AccessKeyPressedEventArgs(key); element.RaiseEvent(args); info.Scope = args.Scope; info.target = args.Target; if (info.Scope == null) { info.Scope = GetSourceForElement(element); } } else { info.Scope = CriticalGetActiveSource(); } return info; }
private void RightClick(IInputElement element) { element.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Right) { RoutedEvent = Mouse.MouseDownEvent }); element.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Right) { RoutedEvent = Mouse.MouseUpEvent }); DispatcherUtil.DoEvents(); }
private void RaiseMouseLeaveNode(IInputElement nv) { View.Dispatcher.Invoke(() => { nv.RaiseEvent(new MouseEventArgs(Mouse.PrimaryDevice, 0) { RoutedEvent = Mouse.MouseLeaveEvent }); }); DispatcherUtil.DoEvents(); }
private static void OnDeactivateStoryboardCompleted( IInputElement snackbar, SnackbarMessage message) { var args = new SnackbarMessageEventArgs(DeactivateStoryboardCompletedEvent, message); snackbar.RaiseEvent(args); }