UIElement.IsMouseCaptured 屬性

定義

取得值,指出是否將滑鼠擷取至這個項目。 這是相依性屬性。

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

屬性值

如果項目具有滑鼠擷取,則為 true;否則為 false。 預設為 false

實作

範例

下列範例會根據是否已針對 專案擷取滑鼠來開啟或關閉滑鼠擷取狀態。

如果滑鼠擷取位於其他地方,滑鼠擷取就會設定為該專案。 如果專案具有滑鼠擷取,則會使用 Null 輸入呼叫 Mouse.Capture 來清除它。

    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

適用於

另請參閱