ContentElement.IsMouseCaptured ContentElement.IsMouseCaptured ContentElement.IsMouseCaptured ContentElement.IsMouseCaptured Property

定義

取得值,這個值表示滑鼠是否由這個項目所捕捉。Gets a value that indicates whether the mouse is captured by this element.

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 by the element.

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 None

適用於

另請參閱