Thursday, February 23, 2012

WPF : An introduction to EventManger class

I am going to introduce EventManager class, Lets look at definition available for EventManager class in VS

#region Assembly PresentationCore.dll, v4.0.30319
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\PresentationCore.dll
#endregion
using MS.Internal.PresentationCore;
using System;
using System.Runtime;
 
namespace System.Windows
{
    public static class EventManager
    {
        public static RoutedEvent[] GetRoutedEvents();
        public static RoutedEvent[] GetRoutedEventsForOwner(Type ownerType);
        [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
        public static void RegisterClassHandler(Type classType, RoutedEvent routedEvent, Delegate handler);
        public static void RegisterClassHandler(Type classType, RoutedEvent routedEvent, Delegate handler, bool handledEventsToo);
        public static RoutedEvent RegisterRoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType);
    }
}


So, as we can see that 
  • Its defined in PresentationCore dll.
  • It exposes a GetRoutedEvents function which can be used to find all RoutedEvent which have been defined in current application. A simple call to GetRoutedEvents in a blank WPF application returns 135 events as can be seen below.
  • It exposes GetRoutedEventsForOwner method which takes a particular class type or control and returns all Routed events defined in that class/control.
  • It exposes RegisterClassHandler method which is used to declare a class level routed event handle. Class level routed event handler are called first before raising any other handler for a particular routed event.
  • It exposes RegisterRoutedEvent method which is used to declare routed event.

No comments:

Post a Comment