UIElement.IsMouseCaptured UIElement.IsMouseCaptured UIElement.IsMouseCaptured UIElement.IsMouseCaptured Property

定義

取得值,指出是否將滑鼠擷取至這個項目。Gets a value indicating whether the mouse is captured to this element. 這是相依性屬性。This is a dependency property.

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

如果滑鼠捕捉位於其他地方, 滑鼠捕捉會設定為該元素。If mouse capture is elsewhere, the mouse capture is set to that element. 如果專案具有滑鼠捕捉, 則會使用 null 輸入呼叫Mouse.Capture來清除它。If the element had mouse capture, it is cleared by calling Mouse.Capture with a null input.

    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

適用於

另請參閱