|
|||||||||
Writing the Logic Using Visual Basic Double-click the Page.xaml.vb file in Solution Explorer to load it in the code editor.
In the Page_Loaded() subroutine, add the following bolded lines:
In the preceding code, the Timeline1 triggers an event (the Completed event) each second (set through the Duration object). The Timeline object is somewhat similar to the Timer control that Windows developers are familiar with. The Begin() method starts the countdown and one second later the Completed event is fired.
The next step would be to service the Completed event, which you can easily do by first selecting the Timeline1 object from the top of the code editor, and then selecting its corresponding Completed event (see Figure 14).
Code the Completed event handler as follows:
Basically, you set the current time by retrieving the TextBlock control embedded within the canvas (btnTime) and setting its Text property. The canvas has two children:
That's it! Press F5 in Visual Studio 2008 and you will see your Silverlight application displayed in Internet Explorer. If you load the sample application in FireFox, it will look and work the same (see Figure 15). The button will update the time every second.
|
|||||||||
|
Submit article to:
|