ContentElement.ReleaseMouseCapture Method

Definition

Releases the mouse capture, if this element held the capture.

C#
public void ReleaseMouseCapture();

Implements

Examples

The following handler captures or releases mouse capture according to mouse button states. The example shows how to use captured mouse movement for alternative purposes other than moving the mouse pointer in the UI.

C#
private void MouseDownHandler(object sender, MouseButtonEventArgs e)
{
    ContentElement el = (ContentElement)sender;
    if (!el.IsEnabled) return;
    e.Handled = true;
    el.CaptureMouse();
    _point = e.MouseDevice.GetPosition(el); 
}

private void MouseUpHandler(object sender, MouseButtonEventArgs e)
{
    ContentElement el = (ContentElement)sender;
    if (!el.IsEnabled) return;
    e.Handled = true;
    el.ReleaseMouseCapture();
}

Remarks

If this element did not hold the capture, calling this method has no effect. Consider checking the value of IsMouseCaptured before you call this method.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also