Пример #1
0
        private void AddToEventRouteImpl(EventRoute route, RoutedEventArgs args)
        {
            //
            // add class listeners then instance listeners.
            //
            Hashtable store = _classEventHandlersStore;
            RoutedEvent evt = args._routedEvent;
            for (int repeat = 0; repeat < 2; repeat++)
            {
                if (store != null)
                {
                    ArrayList eventListeners = (ArrayList)store[evt];

                    // Add all listeners for this UIElement
                    if (eventListeners != null)
                    {
                        for (int i = 0, count = eventListeners.Count; i < count; i++)
                        {
                            RoutedEventHandlerInfo eventListener = (RoutedEventHandlerInfo)eventListeners[i];
                            route.Add(this, eventListener._handler, eventListener._handledEventsToo);
                        }
                    }
                }

                store = _instanceEventHandlersStore;
            }
        }
Пример #2
0
        /// <summary>
        ///     Add the event handlers for this element to the route.
        /// </summary>
        // REFACTOR -- do we need this to be public?
        public void AddToEventRoute(EventRoute route, RoutedEventArgs args)
        {
            if (route == null || args == null)
                throw new ArgumentNullException();

            AddToEventRouteImpl(route, args);
        }
Пример #3
0
        /// <summary>
        ///     Raise the events specified by
        ///     <see cref="RoutedEventArgs.RoutedEvent"/>
        /// </summary>
        /// <remarks>
        ///     This method is a shorthand for
        ///     This method walks up the visual tree, calling
        ///     <see cref="UIElement.BuildRouteCore"/>
        ///     on every <see cref="UIElement"/> <para/>
        ///     <para/>
        ///
        ///     NOTE: The RoutedEvent in RoutedEventArgs
        ///     and EventRoute must be matched
        ///
        ///     Once the route is built, it calls InvokeHandlers()
        /// </remarks>
        /// <param name="args">
        ///     <see cref="RoutedEventArgs"/> for the event to
        ///     be raised
        /// </param>
        public void RaiseEvent(RoutedEventArgs args)
        {
            if (args == null)
                throw new ArgumentNullException();

            EventRoute route = new EventRoute(args._routedEvent);

            // Set Source
            args.Source = this;

            // direct.
            if (args._routedEvent._routingStrategy == RoutingStrategy.Direct)
            {
                AddToEventRouteImpl(route, args);
            }
            else
            {
                int cElements = 0;

                UIElement uiElement = this;

                do
                {
                    // Protect against infinite loops by limiting the number of elements
                    // that we will process.
                    if (cElements++ > MAX_ELEMENTS_IN_ROUTE)
                    {
                        throw new InvalidOperationException(/*SR.Get(SRID.TreeLoop) */);
                    }

                    uiElement.AddToEventRouteImpl(route, args);

                    uiElement = uiElement._parent;

                } while (uiElement != null);
            }

            route.InvokeHandlers(this, args);

            // Reset Source to OriginalSource
            args.Source = args.OriginalSource;
        }