UIElement.IsMouseCaptured 屬性

定義

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

C#
public bool IsMouseCaptured { get; }

屬性值

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

實作

範例

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

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

C#
    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);
            }
        }
    }

備註

滑鼠擷取狀態與進程內拖放作業有關。

相依性屬性資訊

識別碼欄位 IsMouseCapturedProperty
設定為 的中繼資料屬性 true

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱