Click here to Skip to main content
6,306,412 members and growing! (23,940 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Windows Presentation Foundation » General     Beginner License: The Code Project Open License (CPOL)

Digital Clock using Silverlight and JavaScript

By Anandraj

Digital Clock using Silverlight and JavaScript
C#, Javascript, Windows, .NET, Visual Studio, WPF, Dev
Posted:5 Jul 2007
Views:22,462
Bookmarked:15 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
11 votes for this article.
Popularity: 2.98 Rating: 2.86 out of 5
2 votes, 18.2%
1
2 votes, 18.2%
2
4 votes, 36.4%
3
1 vote, 9.1%
4
2 votes, 18.2%
5
Screenshot - DigiClock.gif

Introduction

This article will explain how we can use Silverlight using JavaScript.

Background

This digital clock has been developed using Silverlight and JavaScript. We have four different files here. The XAML file will have code to display the numbers using different shapes like rectangle and polygon. If you know VML, then this XAML file will have the same syntax.

Using the Code

Here, we will see a different file separately. Before you start using Silverlight, you have to download the Silverlight Plugin.

1. DigiClock.htm

This file will be executed by the browser to show the digital clock. First, add the JavaScript references to this page. Then, declare a container where the Silverlight control will be loaded. Below this, get the Container object and call the function createMySilverlightDigiClock();

<script src="Silverlight.js"></script>
<script src="my-script.js"></script>
</head>
<body>
<!-- Container-->
<div id="DigiClock">
</div>
<script type="text/javascript">
// Create Container Object.
var parentElement = document.getElementById("DigiClock");
// This function creates the Silverlight control.
createMySilverlightDigiClock();
</script>

2. Silverlight.js

This file has to be downloaded from the Internet. This file will contain the methods to create a Silverlight control and other helper methods.

3. My-Script.js

This file will contain my custom JavaScript functions to show the digital display.

  • createMySilverlightDigiClock() - This method will be called from the DigiClock.htm file which will create a Silverlight control, where you have to specify the XAML file name, your container name, width and height of the Silverlight control.
  • ShowNumber(sender,num,strTime) - This method will show the number in the display depending on the parameters passed.
    • sender - Silverlight control object
    • num - Number to show in the display
    • strTime - Variable containing the place where this number has to be shown on the display board
  • OnLoad() - This method will be called on load of the page where the Silverlight control will be stored in a global variable called Canvas and ClearDisplay() will be called to clear the previously displayed number. Then, call the ShowCurrentTime() to show the present time in the display.
  • ClearDisplay() - This method will clear the number in the display. This is done by changing the Opacity of the Polygon. This property (Opacity) will take the value from 0 to 1. where 0 will not show the object and 1 will show the object with full color.
  • ShowCurrentTime() - This method will be used to update the display with the current time. Current time will be taken using the JavaScript and it will update the display with the current time and this function will be called at regular intervals to update the display.

4. digiclock.xaml

This file is the most important file where you have to define all the shapes you are going to use in your application. Here, I have created a single digit with seven polygons and each polygon's Opacity will be changed depending on the time.

Note: I have also added my name at the bottom using PolyLine and Path Elements.

Points of Interest

I am working with .NET for the past 4 years. My areas of interest include .NET, AJAX and other new upcoming technologies.

History

  • 5th July, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Anandraj


Member
I am working as a Senior Associate.
Occupation: Web Developer
Location: India India

Other popular Windows Presentation Foundation articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Jul 2007
Editor: Deeksha Shenoy
Copyright 2007 by Anandraj
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project