예제 #1
0
        /// <inheritdoc />
        public override AutomationEventHandlerBase RegisterAutomationEvent(EventId @event, TreeScope treeScope, Action <SHAutomationElement, EventId> action)
        {
            var eventHandler = new UIA3AutomationEventHandler(this, @event, action);

            Automation.NativeAutomation.AddAutomationEventHandler(@event.Id, NativeElement, (UIA.TreeScope)treeScope, null, eventHandler);
            return(eventHandler);
        }
예제 #2
0
        /// <summary>Request notififications about <paramref name="eventId" /></summary>
        /// <param name="element">Target element</param>
        /// <param name="eventId">Event to be notified about</param>
        /// <param name="treeScope">Scope to monitor</param>
        /// <param name="autoRelease">Whether to automatically unregister event when object is Disposed</param>
        /// <param name="action">Callback</param>
        /// <returns></returns>
        protected AutomationEventHandlerBase RegisterAutomationEventInternal(
            AutomationElement element,
            EventId eventId,
            TreeScope treeScope,
            bool autoRelease,
            Action <AutomationElement, EventId> action)
        {
            var automationElement = element ?? UIAuto.GetDesktop();
            var desktopEl         = (UIA3FrameworkAutomationElement)automationElement.FrameworkAutomationElement;
            var eventHandler      = new UIA3AutomationEventHandler(desktopEl,
                                                                   eventId,
                                                                   action);

            UIAuto.NativeAutomation.AddAutomationEventHandler(
                eventId.Id,
                desktopEl.NativeElement,
                (global::Interop.UIAutomationClient.TreeScope)treeScope,
                null,
                eventHandler
                );

            if (autoRelease)
            {
                _registeredEvents.Add((automationElement, eventHandler));
                return(null);
            }

            return(null);
        }