private void OnTargetChanged(IInputElement oldTarget, IInputElement newTarget) { int timestamp = presentationSource.GetTimestamp(); if (oldTarget != null) { foreach (Key key in downKeys) { oldTarget.RaiseEvents( new KeyEventArgs(Keyboard.PreviewKeyUpEvent, oldTarget, this, timestamp, key, KeyStates.None, false), new KeyEventArgs(Keyboard.KeyUpEvent, oldTarget, this, timestamp, key, KeyStates.None, false)); } oldTarget.RaiseEvents( new KeyboardFocusChangedEventArgs(Keyboard.PreviewLostKeyboardFocusEvent, oldTarget, this, timestamp, oldTarget, newTarget), new KeyboardFocusChangedEventArgs(Keyboard.LostKeyboardFocusEvent, oldTarget, this, timestamp, oldTarget, newTarget)); } if (newTarget != null) { newTarget.RaiseEvents( new KeyboardFocusChangedEventArgs(Keyboard.PreviewGotKeyboardFocusEvent, newTarget, this, timestamp, oldTarget, newTarget), new KeyboardFocusChangedEventArgs(Keyboard.GotKeyboardFocusEvent, newTarget, this, timestamp, oldTarget, newTarget)); foreach (Key key in downKeys) { newTarget.RaiseEvents( new KeyEventArgs(Keyboard.PreviewKeyDownEvent, newTarget, this, timestamp, key, KeyStates.None, false), new KeyEventArgs(Keyboard.KeyDownEvent, newTarget, this, timestamp, key, KeyStates.None, false)); } } }
public void Deactivate() { IInputElement lastTarget = Target; IsActive = false; if (lastTarget != null) { int timestamp = presentationSource.GetTimestamp(); foreach (MouseButton button in pressedButtons) { lastTarget.RaiseEvents( new MouseButtonEventArgs(Mouse.PreviewMouseUpEvent, lastTarget, this, timestamp, Position, button, MouseButtonState.Released, 1), new MouseButtonEventArgs(Mouse.MouseUpEvent, lastTarget, this, timestamp, Position, button, MouseButtonState.Released, 1)); } } pressedButtons.Clear(); }