UIElement.IsMouseCaptured UIElement.IsMouseCaptured UIElement.IsMouseCaptured UIElement.IsMouseCaptured Property

定义

获取一个值,该值指示此元素是否捕获了鼠标。Gets a value indicating whether the mouse is captured to this element. 这是依赖项属性。This is a dependency property.

public:
 property bool IsMouseCaptured { bool get(); };
public bool IsMouseCaptured { get; }
member this.IsMouseCaptured : bool
Public ReadOnly Property IsMouseCaptured As Boolean

属性值

如果元素具有鼠标捕获,则为 true;否则为 falsetrue if the element has mouse capture; otherwise, false. 默认值为 falseThe default is false.

实现

示例

下面的示例根据是否已为元素捕获鼠标, 打开或关闭鼠标捕获状态。The following example turns the mouse capture state on or off based on whether the mouse is already captured for the element.

如果鼠标捕获在其他位置, 则将鼠标捕获设置为该元素。If mouse capture is elsewhere, the mouse capture is set to that element. 如果元素具有鼠标捕获, 则通过使用空输入调用Mouse.Capture来清除它。If the element had mouse capture, it is cleared by calling Mouse.Capture with a null input.

private void CaptureMouseCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
    MessageBox.Show("Mouse Command");
    IInputElement target = Mouse.DirectlyOver;

    target = target as Control;
    if (target != null)
    {
        if (!target.IsMouseCaptured)
        {
            Mouse.Capture(target);
        }
        else
        {
            Mouse.Capture(null);
        }
    }
}
Private Sub CaptureMouseCommandExecuted(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
    MessageBox.Show("Mouse Command")
    Dim target As IInputElement = Mouse.DirectlyOver

    target = TryCast(target, Control)
    If target IsNot Nothing Then
        If Not target.IsMouseCaptured Then
            Mouse.Capture(target)
        Else
            Mouse.Capture(Nothing)
        End If
    End If
End Sub

注解

鼠标捕获状态与进程内拖放操作相关。Mouse capture state is related to in-process drag-and-drop operations.

依赖项属性信息Dependency Property Information

标识符字段Identifier field IsMouseCapturedProperty
元数据属性设置为trueMetadata properties set to true NoneNone

适用于

另请参阅