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

RemoveAutomationPropertyChangedEventHandler() public static method

public static RemoveAutomationPropertyChangedEventHandler ( AutomationElement element, AutomationPropertyChangedEventHandler eventHandler ) : void
element AutomationElement
eventHandler AutomationPropertyChangedEventHandler
return void
        public static void RemoveAutomationPropertyChangedEventHandler(AutomationElement element, AutomationPropertyChangedEventHandler eventHandler)
        {
            Utility.ValidateArgumentNonNull(element, "element");
            Utility.ValidateArgumentNonNull(eventHandler, "eventHandler");
            
            try
            {
                PropertyEventListener listener = (PropertyEventListener)ClientEventList.Remove(AutomationElement.AutomationPropertyChangedEvent, element, eventHandler);
                Factory.RemovePropertyChangedEventHandler(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 PropertyEventTest()
        {
            int eventCount = 0;
            AutomationProperty changedProperty            = null;
            object             newValue                   = null;
            object             sender                     = null;
            AutomationPropertyChangedEventHandler handler = (o, e) =>
            {
                eventCount++;
                changedProperty = e.Property;
                newValue        = e.NewValue;
                sender          = o;
            };

            At.AddAutomationPropertyChangedEventHandler(
                AutomationElement.RootElement, TreeScope.Children,
                handler, AutomationElement.NameProperty);
            RunCommand("change title:title 1");
            Assert.AreEqual(1, eventCount, "count of AutomationPropertyChangedEvent");
            Assert.AreEqual(AutomationElement.NameProperty, changedProperty);
            Assert.AreEqual("title 1", newValue);
            Assert.AreEqual(testFormElement, sender);
            At.RemoveAutomationPropertyChangedEventHandler(
                AutomationElement.RootElement, handler);
            RunCommand("change title:title 2");
            Assert.AreEqual(1, eventCount);
        }
All Usage Examples Of System.Windows.Automation.Automation::RemoveAutomationPropertyChangedEventHandler