/// <summary> /// Captures the cursor to the specified element. /// </summary> /// <param name="element">The element to which to assign capture.</param> /// <param name="mode">The capture mode to apply.</param> /// <returns><see langword="true"/> if the cursor was captured; otherwise, <see langword="false"/>.</returns> public Boolean Capture(IInputElement element, CaptureMode mode) { if ((element != null && mode == CaptureMode.None) || (element == null && mode != CaptureMode.None)) { throw new ArgumentException(nameof(mode)); } if (withCapture == element) { return(true); } if (!(element?.IsValidForInput() ?? false)) { return(false); } if (withCapture != null) { Release(); } withCapture = element; captureMode = mode; var uiElement = withCapture as UIElement; if (uiElement != null) { SetIsCaptured(uiElement, true); UpdateIsCaptureWithin(uiElement, true); UpdateIsOver(uiElement); RaiseGotCapture(uiElement); } return(true); }