ContentElement.IsMouseCaptured 属性

定义

获取一个值,该值指示此元素是否捕获了鼠标。

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

属性值

Boolean

如果元素具有鼠标捕获,则为 true;否则为 false。 默认值为 false

实现

示例

以下示例根据元素是否已捕获鼠标来打开或关闭鼠标捕获状态。

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

注解

鼠标捕获状态与进程内拖放操作相关。

依赖项属性信息

标识符字段 IsMouseCapturedProperty
元数据属性设置为 true

适用于

另请参阅