共用方式為


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

適用於

另請參閱