다음을 통해 공유


WindowPattern.WindowClosedEvent 필드

정의

창이 닫힐 때 발생하는 이벤트를 식별합니다.

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 대리자에 대해 지정 된 WindowOpenedEventWindowClosedEvent 이벤트입니다.

///--------------------------------------------------------------------
/// <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

설명

창이 닫히는 즉시 UI 자동화 컨트롤 뷰 구조에서 제거되므로 클라이언트 애플리케이션은 캐시된 개체에서 수신 대기 WindowClosedEvent 해야 할 수 있습니다.

이 식별자는 UI 자동화 클라이언트 애플리케이션에서 사용 됩니다. UI 자동화 공급자의 해당 필드를 사용 해야 WindowPatternIdentifiers합니다.

적용 대상

추가 정보