Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » General » Getting Started with silverlight

Getting Started with silverlight

This article explains you how to use silverlight and also gives you a brief history behind silverlight.

Technologies: .NET 1.0/1.1, XAML,Visual C# .NET
Total downloads :
Total page views :  7897
Rating :
 0/5
This article has been rated :  0 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
Become a Sponsor



Getting Started with Silverlight

One of the most talked about aspects of Silverlight is its undeniable technical accomplishments. In an age of 50 megabyte downloads, Microsoft managed to squeeze large parts of WPF and a mini CLR into a tiny browser plug in, currently under 5MB. Not only that, but it runs in the three major browsers (Firefox, Safari and IE) and more amazingly on the three major operating systems, with Microsoft supporting Windows and Mac OS X and Novell Mono project providing a Linux runtime.

This article explains a little of the history behind Silverlight and what you can use it for. You will see how easy it is to get started, and then you will actually practice using a free InnerWorkings coding challenge featuring a sample app that demonstrates how to use and transform video in Silverlight.

Silver-what?

Windows Presentation Foundation Everywhere (WPF/E) was announced two years ago at the 2005 PDC (Professional Developer Conference), but kept a low profile for a long time. At Mix 07 in May however, the first 1.0 beta was released under the Silverlight name, along with (a little confusingly) a preview of the 1.1 release.

Version 1.0 has now been officially released and can display vector graphics, animations and high quality video (up to 720p, the low end of HD). You can program it using a subset of WPF XAML syntax, using JavaScript to provide interactivity.

Version 1.1 however still in technical preview stage is what got everyone excited. Much more than a minor revision, this adds a bite sized CLR to the plug in, capable of executing compiled C#, VB, Python and Ruby code. Though it is cut down, the Core CLR still provides a just in time compiler and works with the exact same assemblies as the full blown desktop CLR. If you can restrict yourself to the smaller set of classes included with Silverlight CLR, there is complete compatibility between the two, with no recompilation necessary.

How does Silverlight work?

From a user point of view, the experience is designed to be as smooth as possible. On visiting a Silverlight enabled site for the first time, a message appears inviting the user to download the plug in from the Microsoft site. The install is quick and painless, although it can require a browser restart. After that, any Silverlight content is displayed automatically and the plug in even updates itself as required.

The Silverlight SDK makes this experience easy by providing a JavaScript file that detects the plug in presence and either just displays the content or prompts the user to install. The JavaScript also provides a way to display Silverlight content without worrying about the different expectations of the supported browsers.

The actual scene is defined in XAML, an XML based format where elements and attributes correspond to .NET objects and their properties. This is the same XAML that powers WPF, just with some of the elements missing.

What's left, at least in Silverlight 1.0, is enough to draw shapes, images, text and video. Some of the flexible layout options from WPF (like the Grid, DockPanel and StackPanel) are missing, along with any kind of prebuilt UI control there are no buttons, menus, listboxes or anything. Though you can use HTML controls instead, this is a major shortcoming, and the Silverlight team have promised some of these controls for a future release of version 1.1, along with a set of panels to make layout easier.

To build an app that does more than just look pretty, you can attach event handlers to Silverlight objects and write code that manipulates the scene, starting animations, controlling video or audio playback and updating the properties of objects. Silverlight really does behave like a mini WPF, so if you are familiar with its big brother (or Windows Forms or ASP.NET for that matter), the programming model is easy to follow.

Hello, Silverlight

When you strip away the helper JavaScript files, very little is required to display Silverlight content in a browser that has the plug in installed. The snippet below uses inline XAML to reference content defined in the HTML file, but you can just as easily use a file located on your web server (or one generated dynamically by ASP.NET).

Other than the XAML script tag, the snippet contains an object tag that actually creates an instance of the Silverlight control, passing it a reference to the XAML it should use (in this case preceded by the # symbol to specify the ID of the HTML element with the content).

<
html xmlns="http://www.w3.org/1999/xhtml">
<body>
<script type="text/xaml" id="xamlContent">
<Canvas xmlns="http://schemas.microsoft.com/client/2007">
<TextBlock Text=
"Hello, Silverlight!" />
</Canvas>
</script>
<object id="silverlightObj" type="application/x-silverlight" width="200" height="200">
<param name="source" value="#xamlContent" />
</object>
</body>
</
html>

Displaying video with Silverlight

One of the strengths of WPF (and so Silverlight) is its composability: objects can be nested within each other easily to create composite objects. A button, for example, does not have to contain just a text label, it could contain an image as well (or a video, or a tiny interactive game, or whatever you want). While many of these uses are not, well, useful, the simplicity that composability affords helps with all sorts of more common scenarios. If you want to display an image or video inside a circle or a rounded rectangle, you do not have to set some obscure property of the image, you just pop it inside a suitably shaped container.

In the same way, Silverlight animation and transformation features can apply to video as easily as primitive shapes. This makes it easy to render video on objects that can be dragged around, or to zoom into or clip video. The key to this is the VideoBrush, which can be used to paint the interior of a shape with the output of a MediaElement. The MediaElement itself can then be hidden, leaving only the VideoBrush painted shape visible.

Try it out

Silverlight is one of those technologies where words alone can not possibly do it justice. Have a look at the tutorials at
http://silverlight.net/ to find out more, or skip ahead to http://silverlight.net/showcase/ to see what can be done.

Next, download the free Silverlight challenges from InnerWorkings and get to grips with some real Silverlight projects. You will learn more about setting up Silverlight in your own apps, as well as practice using a VideoBrush to render and control video clipped and magnified according to your own specifications.

What's an InnerWorkings coding challenge?

An InnerWorkings coding challenge is a sample of code in Visual Studio that has some key pieces missing. Each challenge includes selected reference links chosen specifically to help you find out how to fill in the blanks, complete the sample app, and learn about a new technology at the same time. Once you are finished, InnerWorkings Developer automatically checks your code so you can be sure you have solved the challenge correctly and that you really understand what you have learned.

Our coding challenges are designed to take you to the heart of the technology you want to learn more about, focusing on the most important, practical features. Because everything has been set up for you, you can dive straight in and start coding.

InnerWorkings has a library of hundreds of challenges on diverse topics from ASP.NET to Windows Communication Foundation. For more information, have a look at our catalog.


Login to add your contents and source code to this article
 [Top] Rate this article
 About the author
 
Michael O Brien
Michael O’Brien lives in Dublin, Ireland where he works for InnerWorkings. He currently concentrates on the software that allows InnerWorkings Developer to check code solutions submitted to the code judging engine. When he’s not knee-deep in System.Reflection, he likes to play with ASP.NET and a little bit of Ruby.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other Visual Studio release. Work more productively and collaboratively-with greater control over your work at every step. The Beta 2 can give you a head start on achieving efficiency.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Become a Sponsor
 Comments
hi by Nikhil On April 18, 2009
thanks for your help
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved