What you need to know about routed events in WPF (similar to Silverlight)

Events in WPF (and Silverlight) are dealt with differently, using “Routing Events”.  Why?

  • Routed events enable you to add multiple levels of complexity to your UIs and the response to user input.

What do you need to know about the concept of routed events:

  • How to handle a routed event
  • Define and register a new routed event
  • Handle an application lifetime event
    • http://msdn.microsoft.com/en-us/library/ms748948.aspx#WindowLifetime
    • This can be confusing, but it relates
      • Activated
        • Occurs when you switch from another application to your program. It also is raised the first time you show a window
      • Deactivated Deactivated
        • Occurs when you switch to another program DispatcherUnhandledException DispatcherUnhandledException Raised when an unhandled exception occurs in your application.
      • Exit
        • Occurs when the application is shut down or any reason
      • SessionEnding
        • Occurs when the Windows session is ending, such as when the user shuts down the computer or logs off
      • Startup Startup
        • Occurs as the application is started.
  • Use the EventManager class
    • GetRoutedEvents
      • Returns an array that contains all the routed events that have been registered in this application
    • GetRoutedEventsForOwner
      • Returns an array of all the routed events that have been registered for a specified element in this application
    • RegisterClassHandler
      • Registers a class-level event handler
    • RegisterRoutedEvent
      • An instance-level event handler
Comments (0)

Skip to main content