Beispiel #1
0
        /// <summary>
        /// Gets the next event handler to invoke for the current element.
        /// </summary>
        /// <param name="element">The element for which event handlers are being invoked.</param>
        /// <param name="evt">A <see cref="RoutedEvent"/> which identifies the routed event for which handlers are being invoked.</param>
        /// <param name="index">The index of the handler to invoke; this value is incremented by one when this method returns.</param>
        /// <param name="handler">The metadata for the handler that corresponds to the specified index within the handler list.</param>
        /// <returns><see langword="true"/> if a handler was retrieved for the specified index; otherwise, <see langword="false"/>.</returns>
        private static Boolean GetEventHandler(DependencyObject element, RoutedEvent evt, ref Int32 index, ref RoutedEventHandlerMetadata handler)
        {
            var indexTemp = index;

            var classHandlers = RoutedEventClassHandlers.GetClassHandlers(element.GetType(), evt);

            if (classHandlers != null)
            {
                lock (classHandlers)
                {
                    if (indexTemp >= 0 && indexTemp < classHandlers.Count)
                    {
                        handler = classHandlers[indexTemp];
                        index++;
                        return(true);
                    }
                    indexTemp -= classHandlers.Count;
                }
            }

            var uiElement = element as UIElement;

            if (uiElement != null)
            {
                var instanceHandlers = uiElement.GetHandlers(evt);
                if (instanceHandlers == null)
                {
                    return(false);
                }

                lock (instanceHandlers)
                {
                    if (indexTemp >= instanceHandlers.Count)
                    {
                        return(false);
                    }
                    handler = instanceHandlers[indexTemp];
                    index++;
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
 /// <summary>
 /// Registers a class handler for a routed event.
 /// </summary>
 /// <param name="classType">The type of the class that is declaring class handling.</param>
 /// <param name="routedEvent">A <see cref="RoutedEvent"/> which identifies the event to handle.</param>
 /// <param name="handler">The delegate that represents the class handler to register.</param>
 /// <param name="handledEventsToo">A value indicating whether to invoke the handler even if it has already been handled.</param>
 public static void RegisterClassHandler(Type classType, RoutedEvent routedEvent, Delegate handler, Boolean handledEventsToo)
 {
     RoutedEventClassHandlers.RegisterClassHandler(classType, routedEvent, handler, handledEventsToo);
 }
 /// <summary>
 /// Registers a class handler for a routed event.
 /// </summary>
 /// <param name="classType">The type of the class that is declaring class handling.</param>
 /// <param name="routedEvent">A <see cref="RoutedEvent"/> which identifies the event to handle.</param>
 /// <param name="handler">The delegate that represents the class handler to register.</param>
 public static void RegisterClassHandler(Type classType, RoutedEvent routedEvent, Delegate handler)
 {
     RoutedEventClassHandlers.RegisterClassHandler(classType, routedEvent, handler);
 }