This is a mirror of official site: http://jasper-net.blogspot.com/

TIP: Routed events in Silverlight

| Monday, June 13, 2011
The use of events in Silverlight, like every other programming platform, is something usual to every programmer. Attaching the click of a button, handling the change of the index in a ComboBox, managing the mouse events to implement drag and drop of UI elements, all these tasks are so natural like ages ago it was usual to write a "gosub" to change the flow of a program written in BASIC.

Nevertheless not all the people are aware that, it exists a interesting category of events, the so-called "Routed Events", that have a special behavior. They appear very similar to every other event exposed by an element, but they are able to route the event from the innermost to the outermost in the case that multiple elements raise the same event at the same time.

As an example you can think about having three Border nested one inside the other. In this condition if you attach the MouseLeftButtonDown event of every Border when you click on the inner element you will see that the event is raised one time for each border. This happen because the MouseLeftButtonDown event is passed from the innermost Border element, to the second and finally to the third element. This is what it mean the term Routing, usually called also Bubbling.

Routed events are recognizable because the argument of the handler method is of type RoutedEventArgs or of another class derived from it. However they are limited to a small number of events that I list here: 
  • KeyDown
  • KeyUp
  • GotFocus
  • LostFocus
  • MouseLeftButtonDown
  • MouseLeftButtonUp
  • MouseMove
  • MouseWheel
  • BindingValidationError
  • DragEnter
  • DragLeave
  • DragOver
  • Drop

Read more: Silverlight Show

Posted via email from Jasper-net

0 comments: