WindowPattern.WindowClosedEvent Pole

Definicja

Identyfikuje zdarzenie, które jest zgłaszane po zamknięciu okna.

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 

Wartość pola

Przykłady

W poniższym przykładzie odbiorniki zdarzeń są deklarowane, a AutomationEventHandler delegat jest określony dla WindowOpenedEvent zdarzeń i 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

Uwagi

Aplikacja kliencka może wymagać nasłuchiwania WindowClosedEvent z buforowanego obiektu, ponieważ okno jest usuwane z struktury widoku sterowania automatyzacja interfejsu użytkownika natychmiast po zamknięciu.

Ten identyfikator jest używany przez aplikacje klienckie automatyzacja interfejsu użytkownika. automatyzacja interfejsu użytkownika dostawcy powinni używać odpowiedniego pola w elemencie WindowPatternIdentifiers.

Dotyczy

Zobacz też