WindowPattern.WindowOpenedEvent Поле
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Определяет событие, которое возникает при открытии окна.
public: static initonly System::Windows::Automation::AutomationEvent ^ WindowOpenedEvent;
public static readonly System.Windows.Automation.AutomationEvent WindowOpenedEvent;
staticval mutable WindowOpenedEvent : System.Windows.Automation.AutomationEvent
Public Shared ReadOnly WindowOpenedEvent 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
Комментарии
Этот идентификатор используется клиентскими приложениями автоматизации пользовательского интерфейса. Поставщики автоматизации пользовательского интерфейса должны использовать эквивалентное поле в WindowPatternIdentifiers.