UIElement.IsMouseCaptured 屬性
定義
取得值,指出是否將滑鼠擷取至這個項目。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
;否則為 false
。true
if the element has mouse capture; otherwise, false
. 預設為 false
。The 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 |
中繼資料屬性設定為 true Metadata properties set to true |
NoneNone |