![]() |
Platforms, Frameworks & Libraries »
Windows Presentation Foundation »
General
Beginner
License: The Code Project Open License (CPOL)
Digital Clock using Silverlight and JavaScriptBy AnandrajDigital Clock using Silverlight and JavaScript |
C#, Javascript, Windows, .NET, Visual Studio, WPF, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
This article will explain how we can use Silverlight using JavaScript.
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.
Here, we will see a different file separately. Before you start using Silverlight, you have to download the Silverlight Plugin.
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>
This file has to be downloaded from the Internet. This file will contain the methods to create a Silverlight control and other helper methods.
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 objectnum - Number to show in the displaystrTime - Variable containing the place where this number has to be shown on the display boardOnLoad() - 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.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.
I am working with .NET for the past 4 years. My areas of interest include .NET, AJAX and other new upcoming technologies.
General
News
Question
Answer
Joke
Rant
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 |