WindowPattern.WindowClosedEvent 欄位
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
識別視窗關閉時引發的事件。
public: static initonly System::Windows::Automation::AutomationEvent ^ WindowClosedEvent;
public static readonly System.Windows.Automation.AutomationEvent WindowClosedEvent;
staticval mutable WindowClosedEvent : System.Windows.Automation.AutomationEvent
Public Shared ReadOnly WindowClosedEvent As AutomationEvent
欄位值
範例
在下列範例中,會宣告事件接聽程式,並 AutomationEventHandler 針對 WindowOpenedEvent 和 WindowClosedEvent 事件指定委派。
///--------------------------------------------------------------------
/// <summary>
/// Register for events of interest.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
///--------------------------------------------------------------------
private void RegisterForAutomationEvents(
AutomationElement targetControl)
{
AutomationEventHandler eventHandler =
new AutomationEventHandler(OnWindowOpenOrClose);
Automation.AddAutomationEventHandler(
WindowPattern.WindowClosedEvent,
targetControl, TreeScope.Element, eventHandler);
Automation.AddAutomationEventHandler(
WindowPattern.WindowOpenedEvent,
targetControl, TreeScope.Element, eventHandler);
}
///--------------------------------------------------------------------
/// <summary>
/// AutomationEventHandler delegate.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
///--------------------------------------------------------------------
private void OnWindowOpenOrClose(object src, AutomationEventArgs e)
{
// Make sure the element still exists. Elements such as tooltips
// can disappear before the event is processed.
AutomationElement sourceElement;
try
{
sourceElement = src as AutomationElement;
}
catch (ElementNotAvailableException)
{
return;
}
if (e.EventId == WindowPattern.WindowOpenedEvent)
{
// TODO: event handling
return;
}
if (e.EventId == WindowPattern.WindowClosedEvent)
{
// TODO: event handling
return;
}
}
'''------------------------------------------------------------------------
''' <summary>
''' Register for events of interest.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
'''------------------------------------------------------------------------
Private Sub RegisterForEvents(ByVal targetControl As AutomationElement)
Dim eventHandler As AutomationEventHandler = AddressOf OnWindowOpenOrClose
Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, _
targetControl, TreeScope.Element, eventHandler)
Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, _
targetControl, TreeScope.Element, eventHandler)
End Sub
'''------------------------------------------------------------------------
''' <summary>
''' AutomationEventHandler delegate.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
'''------------------------------------------------------------------------
Private Sub OnWindowOpenOrClose(ByVal src As Object, _
ByVal e As AutomationEventArgs)
' Make sure the element still exists. Elements such as tooltips
' can disappear before the event is processed.
Dim sourceElement As AutomationElement
Try
sourceElement = DirectCast(src, AutomationElement)
Catch
Return
End Try
If e.EventId Is WindowPattern.WindowOpenedEvent Then
' TODO: event handling
Return
End If
If e.EventId Is WindowPattern.WindowClosedEvent Then
' TODO: event handling
Return
End If
End Sub
備註
用戶端應用程式可能需要從快取物件接聽 WindowClosedEvent ,因為視窗會在關閉時立即從 UI 自動化控制項檢視結構中移除。
UI 自動化用戶端應用程式會使用此識別碼。 使用者介面自動化提供者應該使用 中的 WindowPatternIdentifiers 對等欄位。