Controls that raise
command events that are not in those expected by the DataGrid control are wrapped into an
ItemCommand event exposed by the control.
The capabilities provided by a command event are an implementation of event bubbling.
Event bubbling is a technique that allows a child control to propagate command events up its
control hierarchy, allowing the event to be handled in a more convenient location. Figure 5-13
provides a graphical depiction of event bubbling. This technique allows the DataGrid control to
take a crack at handling the button events despite the fact that the buttons are several layers
deep inside of its control hierarchy.
Figure 5-13. Event bubbling
Exposing the Command Event
The techniques used to expose a command event on our control are similar to those used with
the Click event. As before, an important preliminary task to creating the event declaration is
the need for an object to provide a ???key??? that gives access to the event in the Events collection.
The CommandEvent field handles this chore:
212 CHAPTER 5 ?– SE RVER CONTROL EVENTS
private static readonly object CommandEvent = new object();
The event declaration for the Command event is almost identical to the Click event except for
the delegate type used.
Pages:
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314