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

RemoveAllEventHandlers() public static method

public static RemoveAllEventHandlers ( ) : void
return void
        public static void RemoveAllEventHandlers()
        {
            try
            {
                Factory.RemoveAllEventHandlers();
                ClientEventList.Clear();
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }

Usage Example

Exemplo n.º 1
0
        public void InvokeEventTest()
        {
            int eventCount = 0;
            AutomationEventHandler handler = (o, e) => eventCount++;

            At.AddAutomationEventHandler(InvokePattern.InvokedEvent, button1Element,
                                         TreeScope.Element, handler);

            AssertRaises <ArgumentException> (
                () => At.RemoveAutomationEventHandler(AutomationElementIdentifiers.AutomationPropertyChangedEvent, button1Element, handler),
                "AutomationPropertyChangedEvent is not valid");

            //Shall have no effect.
            At.RemoveAutomationEventHandler(InvokePattern.InvokedEvent, testFormElement, handler);
            RunCommand("click button1");
            Assert.AreEqual(1, eventCount, "Invoke event fired");

            eventCount = 0;
            At.RemoveAutomationEventHandler(InvokePattern.InvokedEvent, button1Element, handler);
            RunCommand("click button1");
            Assert.AreEqual(0, eventCount, "Invoke event not fired");
            eventCount = 0;
            //Test for add the same handler again.
            At.AddAutomationEventHandler(InvokePattern.InvokedEvent, button1Element,
                                         TreeScope.Element, handler);
            At.AddAutomationEventHandler(InvokePattern.InvokedEvent, button1Element,
                                         TreeScope.Element, handler);
            RunCommand("click button1");
            Assert.AreEqual(2, eventCount, "Invoke event fired");

            eventCount = 0;
            At.RemoveAllEventHandlers();
            RunCommand("click button1");
            Assert.AreEqual(0, eventCount, "Invoke event not fired");
        }
All Usage Examples Of System.Windows.Automation.Automation::RemoveAllEventHandlers