So far in this chapter I’ve described two Silverlight events—SizeChanged and OrientationChanged—but used them in different ways. For SizeChanged, I associated the event with the event handler in XAML, but for OrientationChanged, I overrode the equivalent OnOrientationChanged method.
Of course, you can attach handlers to events entirely in code as well. One handy class for Silverlight programs is DispatcherTimer, which periodically nudges the program with a Tick event and lets the program do some work. A timer is essential for a clock program, for example.
The content grid of the SilverlightSimpleClock project contains just a centered TextBlock:
Example 2-12. Silverlight Project: SilverlightSimpleClock File: MainPage.xaml ...