WindowPattern.WindowClosedEvent Campo
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Identifica el evento que se genera al cerrar una ventana.
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
Valor de campo
Ejemplos
En el ejemplo siguiente, se declaran agentes de escucha de eventos y se especifica un AutomationEventHandler delegado para WindowOpenedEvent eventos y 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
Comentarios
Es posible que una aplicación cliente tenga que escuchar WindowClosedEvent desde un objeto almacenado en caché, ya que se quita una ventana de la estructura de vista de control de automatización de la interfaz de usuario inmediatamente después de cerrarse.
Las aplicaciones cliente de Automatización de la interfaz de usuario usan este identificador. Los proveedores de automatización de la interfaz de usuario deben usar el campo equivalente en WindowPatternIdentifiers.