Automation.RemoveAutomationEventHandler Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Удаляет указанный обработчик событий модель автоматизации пользовательского интерфейса.
public:
static void RemoveAutomationEventHandler(System::Windows::Automation::AutomationEvent ^ eventId, System::Windows::Automation::AutomationElement ^ element, System::Windows::Automation::AutomationEventHandler ^ eventHandler);
public static void RemoveAutomationEventHandler (System.Windows.Automation.AutomationEvent eventId, System.Windows.Automation.AutomationElement element, System.Windows.Automation.AutomationEventHandler eventHandler);
static member RemoveAutomationEventHandler : System.Windows.Automation.AutomationEvent * System.Windows.Automation.AutomationElement * System.Windows.Automation.AutomationEventHandler -> unit
Public Shared Sub RemoveAutomationEventHandler (eventId As AutomationEvent, element As AutomationElement, eventHandler As AutomationEventHandler)
Параметры
- eventId
- AutomationEvent
Идентификатор события.
- element
- AutomationElement
Элемент модель автоматизации пользовательского интерфейса, для которого удаляется обработчик событий.
- eventHandler
- AutomationEventHandler
Метод обработчика, переданный AddAutomationEventHandler(AutomationEvent, AutomationElement, TreeScope, AutomationEventHandler) для указанного идентификатора события и элемента модель автоматизации пользовательского интерфейса.
Примеры
В следующем примере кода показан добавляемый и удаляемый обработчик событий.
// Member variables.
AutomationElement ElementSubscribeButton;
AutomationEventHandler UIAeventHandler;
/// <summary>
/// Register an event handler for InvokedEvent on the specified element.
/// </summary>
/// <param name="elementButton">The automation element.</param>
public void SubscribeToInvoke(AutomationElement elementButton)
{
if (elementButton != null)
{
Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent,
elementButton, TreeScope.Element,
UIAeventHandler = new AutomationEventHandler(OnUIAutomationEvent));
ElementSubscribeButton = elementButton;
}
}
/// <summary>
/// AutomationEventHandler delegate.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
private void OnUIAutomationEvent(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 == InvokePattern.InvokedEvent)
{
// TODO Add handling code.
}
else
{
// TODO Handle any other events that have been subscribed to.
}
}
private void ShutdownUIA()
{
if (UIAeventHandler != null)
{
Automation.RemoveAutomationEventHandler(InvokePattern.InvokedEvent,
ElementSubscribeButton, UIAeventHandler);
}
}
' Member variables.
Private ElementSubscribeButton As AutomationElement
Private UIAeventHandler As AutomationEventHandler
''' <summary>
''' Register an event handler for InvokedEvent on the specified element.
''' </summary>
''' <param name="elementButton">The automation element.</param>
Public Sub SubscribeToInvoke(ByVal elementButton As AutomationElement)
If (elementButton IsNot Nothing) Then
UIAeventHandler = New AutomationEventHandler(AddressOf OnUIAutomationEvent)
Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, elementButton, _
TreeScope.Element, UIAeventHandler)
ElementSubscribeButton = elementButton
End If
End Sub
''' <summary>
''' AutomationEventHandler delegate.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
Private Sub OnUIAutomationEvent(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 ex As ElementNotAvailableException
Exit Sub
End Try
If e.EventId Is InvokePattern.InvokedEvent Then
' TODO Add handling code.
Else
End If
' TODO Handle any other events that have been subscribed to.
Console.WriteLine("Event: " & e.EventId.ProgrammaticName)
End Sub
Private Sub ShutdownUIA()
If (UIAeventHandler IsNot Nothing) Then
Automation.RemoveAutomationEventHandler(InvokePattern.InvokedEvent, ElementSubscribeButton, UIAeventHandler)
End If
End Sub