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

適用於

另請參閱