Exemplo n.º 1
0
        /// <summary>
        /// Finds a specific <see cref="RoutedEvent"/> identifier for a specific object type.
        /// </summary>
        /// <param name="ownerType">The type to start search with. Base types are included. Must not be null.</param>
        /// <param name="eventName">Name of the event. Must not be null or empty.</param>
        /// <param name="checkBaseTypes"><c>true</c> if all base types up to <see cref="UIElement"/> should be checked as well; <c>false</c> if only <param name="ownerType"/> should be checked</param>
        /// <returns>The routed event identifier or <c>null</c> if not found.</returns>
        public static RoutedEvent GetRoutedEventForOwner(Type ownerType, string eventName, bool checkBaseTypes)
        {
            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }
            if (eventName == null)
            {
                throw new ArgumentNullException("eventName");
            }
            if (String.IsNullOrEmpty(eventName))
            {
                throw new ArgumentException(@"Event name must not be an empty string", "eventName");
            }

            do
            {
                foreach (var routedEvent in GlobalEventManager.GetRoutedEventsForOwner(ownerType))
                {
                    if (routedEvent.Name.Equals(eventName))
                    {
                        return(routedEvent);
                    }
                }
                if (ownerType == typeof(UIElement))
                {
                    break;
                }
                // ReSharper disable once PossibleNullReferenceException
                ownerType = ownerType.BaseType;
                // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
            } while (checkBaseTypes);
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds all <see cref="RoutedEvent"/> identifiers owned by a specified object type.
        /// </summary>
        /// <param name="ownerType">The type to start search with. Base types are included. Must not be null.</param>
        /// <returns></returns>
        public static RoutedEvent[] GetRoutedEventsForOwner(Type ownerType)
        {
            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }

            return(GlobalEventManager.GetRoutedEventsForOwner(ownerType));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Associates another owner with the routed event represented by a <see cref="RoutedEvent"/> instance.
 /// </summary>
 /// <param name="ownerType">The type where the routed event is added. Must not be null.</param>
 /// <returns></returns>
 public RoutedEvent AddOwner(Type ownerType)
 {
     if (ownerType == null)
     {
         throw new ArgumentNullException("ownerType");
     }
     GlobalEventManager.AddOwner(this, ownerType);
     return(this);
 }
Exemplo n.º 4
0
        /// <summary>
        /// REgisteres a class handler for a particular <see cref="RoutedEvent"/> with the option to handle events that have been marked as handled already.
        /// </summary>
        /// <param name="classType">Type of the class that is declaring class handling. Must not be null.</param>
        /// <param name="routedEvent">The <see cref="RoutedEvent"/> identifier of the event to handle. Must not be null.</param>
        /// <param name="handler">A reference to the class handler. Must not be null.</param>
        /// <param name="handledEventsToo"><c>true</c> to invoke the handler, even if the <see>RoutedEventArgs.Handled</see> property has been set to <c>true</c> already;
        /// <c>false</c> to retain the default behavior of not invoking handled events</param>.
        public static void RegisterClassHandler(Type classType, RoutedEvent routedEvent, Delegate handler, bool handledEventsToo)
        {
            if (classType == null)
            {
                throw new ArgumentNullException("classType");
            }
            if (routedEvent == null)
            {
                throw new ArgumentNullException("routedEvent");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            GlobalEventManager.RegisterClassHandler(classType, routedEvent, handler, handledEventsToo);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Registers a new event with the event system.
        /// </summary>
        /// <param name="name">Name of the event. The name must be unique within the owner class. It must not be <c>null</c> or empty.</param>
        /// <param name="routingStrategy">The routing strategy for this event.</param>
        /// <param name="handlerType">The type of the event handler. Can not be <c>null</c></param>
        /// <param name="ownerType">The owner class type of the event. Can not be <c>null</c>.</param>
        /// <returns></returns>
        public static RoutedEvent RegisterRoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (handlerType == null)
            {
                throw new ArgumentNullException("handlerType");
            }
            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentException(@"name must not be an empty string", "name");
            }

            return(GlobalEventManager.RegisterRoutedEvent(name, routingStrategy, handlerType, ownerType));
        }
Exemplo n.º 6
0
 /// <summary>
 /// Returns identifiers for registered <see cref="RoutedEvent"/>s.
 /// </summary>
 /// <returns>An array of registered routed events.</returns>
 public static RoutedEvent[] GetRoutedEvents()
 {
     return(GlobalEventManager.GetRoutedEvents());
 }