public EventHandler()
 {
     _moduleBuilder = CreateModuleBuilder();
     _handlerType   = typeof(RoutedEventHandler);
     _binding       = new EventBinding("Invoke");
     _generator     = CreateGenerator();
 }
예제 #2
0
        //Creates an EventHandler on runtime and registers that handler to the Event specified
        public void BindEvent(DependencyObject owner, string eventName)
        {
            EventName = eventName;
            Owner     = owner;
            Event     = Owner.GetType().GetEvent(EventName, BindingFlags.Public | BindingFlags.Instance);
            if (Event == null)
            {
                throw new InvalidOperationException(String.Format("Could not resolve event name {0}", EventName));
            }

            //Create an event handler for the event that will call the ExecuteCommand method
            EventHandler = EventHandlerGenerator.CreateDelegate(
                Event.EventHandlerType, typeof(CommandBehaviorBinding).GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance), this);
            //Register the handler to the Event
            Event.AddEventHandler(Owner, EventHandler);
        }
 public EmptyEventHandler()
 {
     _moduleBuilder = CreateModuleBuilder();
     _handlerType   = typeof(RoutedEventHandler);
     _generator     = CreateGenerator();
 }