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

RemoveAutomationFocusChangedEventHandler() public static method

public static RemoveAutomationFocusChangedEventHandler ( AutomationFocusChangedEventHandler eventHandler ) : void
eventHandler AutomationFocusChangedEventHandler
return void
        public static void RemoveAutomationFocusChangedEventHandler(AutomationFocusChangedEventHandler eventHandler)
        {
            Utility.ValidateArgumentNonNull(eventHandler, "eventHandler");

            try
            {
                FocusEventListener listener = (FocusEventListener)ClientEventList.Remove(AutomationElement.AutomationFocusChangedEvent, null, eventHandler);
                Factory.RemoveFocusChangedEventHandler(listener);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }

Usage Example

Ejemplo n.º 1
0
        public void SetFocusTest()
        {
            AutomationElement [] expectedFocusedElements = new AutomationElement [] {
                textbox3Element, button2Element
            };

            button2Element.SetFocus();
            AutomationFocusChangedEventHandler handler = (s, e) => actualFocusedElements.Add((AutomationElement)s);

            At.AddAutomationFocusChangedEventHandler(handler);
            actualFocusedElements.Clear();
            textbox3Element.SetFocus();
            Thread.Sleep(100);
            Assert.AreEqual(textbox3Element, AutomationElement.FocusedElement, "FocusedElement");
            button2Element.SetFocus();
            Thread.Sleep(100);
            Assert.AreEqual(button2Element, AutomationElement.FocusedElement, "FocusedElement");
            Thread.Sleep(1000);
            At.RemoveAutomationFocusChangedEventHandler(handler);
            Assert.AreEqual(expectedFocusedElements.Length, actualFocusedElements.Count, "Event handler count");
            for (int i = 0; i < actualFocusedElements.Count; i++)
            {
                Assert.AreEqual(expectedFocusedElements [i], actualFocusedElements [i], "Event handler sender #" + i);
            }
        }
All Usage Examples Of System.Windows.Automation.Automation::RemoveAutomationFocusChangedEventHandler