Formerly code named WPF/e, Silverlight (version 1.0) is now available to download from Microsoft’s web site and Microsoft has already released 1.1 beta for developers.
Note: For the puposes of this article, you’ll concern yourslf with version 1.0 RC.
About the Article
This article is not really a exhaustive in-depth drill down into Silverlight, nor into Sidebar gadget details. Here, all you will attempt to do is to use Silverlight to create a nifty little Vista gadget. In the process, you will tread through some of the commonly used elements and usage scenarios. What is interesting is that you don’t need much of anything to get started. The only pre-requisites are the following:
- The Silverlight plug-in that you can download from here. Install it.
- The Silverlight SDK you can download from here. Install it.
In fact, for the most part—in other words, until you really hit creating a gadget—you won’t even need Vista. XP is just fine because most of your work would be editing some files and refreshing the browser.
I don’t think there are very many guitar fans out here in the CodeGuru community. But I am one and as such, I decided to do a guitar tuner, just because it is a pretty simple tool that lends itself well to being used as a Vista gadget just because of its simplicity.
For those who don’t know what a guitar tuner is, let me explain. The rest can skip this section. A guitar is a stringed instrument. Typically, a guitar has six strings and each string is tuned to a particular frequency to make it easier to play. So, each string, when plucked, will produce a unique sound. The sound of these six strings is typically standardised and called a tuning. Tuning is essentially the sound of each string in relation to the others. There are different tunings such as standard, Drop D, and such. One of the first things guitarists do is to tune their guitars before they start playing. This gives them a known platform to play from. When tuned, all notes sound pleasant; otherwise, all you hear would be cacophony. The guitar tuner assists in this. It just plays the sounds of the six strings, so players can pluck their strings and try to match the sounds. When all strings match the sounds from the tuner, the guitar is said to be tuned. These days, most players use their laptops to check tabs for popular songs online, listen to their favorite songs, and record their own. So, as such, it is useful to have a guitar tuner handy. Hence, the idea to create a gadget out of it.
The basic goals will be these. Please take a look at the image below:
In the image, you see you are mimicing the look of a guitar. You see that there are six strings and a hole in the center (just to make it look like a guitar).
- Tiy want to depict the body of a guitar and the strings. This will familiarize you with the Shape elements, the drawing operations, and other features in XAML.
- When you click on any of the strings, you want to play the sound associated with the string. Also, you want to display a blinking element to indicate the string that is being played. This will familiarize you with the handling events, animating elements, and using media (audio) and such in XAML.
- When you have clicked the string once, the plucking sound of the string that is played should be repeated continously. This is needed to allow the user sufficient time to turn the knobs on their guitars to bring it in unison with the tuner’s sound. This will familairize you with media element and some of its properties.
- When you click on the red button, the sound should stop playing. (You want some way to shut it up when done, right?)
The finished Vista gadget should look like this when docked…
…and like this when undocked