System.Windows.Automation.Automation.RemoveAutomationEventHandler C# (CSharp) Method

RemoveAutomationEventHandler() public static method

public static RemoveAutomationEventHandler ( AutomationEvent eventId, AutomationElement element, AutomationEventHandler eventHandler ) : void
eventId AutomationEvent
element AutomationElement
eventHandler AutomationEventHandler
return void
        public static void RemoveAutomationEventHandler(AutomationEvent eventId, AutomationElement element, AutomationEventHandler eventHandler)
        {
            Utility.ValidateArgumentNonNull(element, "element");
            Utility.ValidateArgumentNonNull(eventHandler, "eventHandler");
            Utility.ValidateArgument(eventId != AutomationElement.AutomationFocusChangedEvent, "Use FocusChange notification instead");
            Utility.ValidateArgument(eventId != AutomationElement.StructureChangedEvent, "Use StructureChange notification instead");
            Utility.ValidateArgument(eventId != AutomationElement.AutomationPropertyChangedEvent, "Use PropertyChange notification instead");

            try
            {
                BasicEventListener listener = (BasicEventListener)ClientEventList.Remove(eventId, element, eventHandler);
                Factory.RemoveAutomationEventHandler(eventId.Id, element.NativeElement, listener);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }

Usage Example

Beispiel #1
0
        public void Z_AutomationEventTest()
        {
            var automationEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationEventArgs)null }
            };
            var automationEvents = automationEventsArray.ToList();

            automationEvents.Clear();

            AutomationEventHandler handler =
                (o, e) => automationEvents.Add(new { Sender = o, Args = e });

            SelectionItemPattern item1 = (SelectionItemPattern)child1Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);

            item1.Select();

            AutomationEvent eventId = SelectionItemPattern.ElementSelectedEvent;

            At.AddAutomationEventHandler(eventId,
                                         treeView1Element, TreeScope.Descendants, handler);

            SelectionItemPattern item2 = (SelectionItemPattern)child2Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);

            item2.Select();
            Thread.Sleep(500);
            At.RemoveAutomationEventHandler(eventId, treeView1Element, handler);
            Assert.AreEqual(1, automationEvents.Count, "event count");
            Assert.AreEqual(child2Element, automationEvents [0].Sender, "event sender");
            Assert.AreEqual(SelectionItemPattern.ElementSelectedEvent, automationEvents [0].Args.EventId, "EventId");
            automationEvents.Clear();

            item1.Select();
            Thread.Sleep(500);
            Assert.AreEqual(0, automationEvents.Count, "event count");
        }
All Usage Examples Of System.Windows.Automation.Automation::RemoveAutomationEventHandler