Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


SSWUG

Reader rating:
Click here to read 2 comments about this article.
Article source: CoDe (2007 Nov/Dec)


Article Pages:  1  2 3 4 - Next >


Catching the (Silver) Light

I’d guess that everyone reading this magazine has heard of Silverlight™. I’ll also guess that not everyone has jumped at the opportunity to “play” with something that had been in beta. The good news is that Silverlight 1.0 is now released! I’ve spent a lot of time with Silverlight since Microsoft made the Community Technology Preview version available as WPF/E. The delta between a Web site without Silverlight and a Web site that allows you to experience the wonderfulness of Silverlight is huge. Before you finish reading this article, I hope you’ll realize how very easy it is to bridge that gap.

Some Basics

Silverlight is a small ActiveX control that gets instantiated onto your Web page, maybe in more than one place. During the instantiation, the control is told to take direction from an XML file. That’s all there is to it! Everything else is involved in either the wiring-up of getting the instantiation going or learning how to “give directions” to the control.

"
If you set the canvas background property to #FFC0C0C0, you will get a gray background that enables you to see the edges of the canvas while working with objects.
"

To keep this discussion simple, I’ll specifically discuss Silverlight 1.0. Since you can use JavaScript to code Silverlight, I don’t need to talk about pre-release versions of Visual Studio.

To get the pieces necessary to add Silverlight to your Web page, first go to http://www.silverlight.net. Choose the Get Started menu. On the next page, under the section called DOWNLOAD THE RUNTIME AND TOOLS, scroll down to "Software Development Kit" and click the link for the "Microsoft Silverlight 1.0 Software Development Kit."

Extract the files downloaded to a folder of your choice. There’s plenty of information in there:

  • QuickStart. A great tutorial. When you finish this article, go through the QuickStart, you won’t be disappointed.
  • Silverlight.chm. The Help file documentation. Many sections have example code.
  • Resources. JavaScript and schema files.

For the purposes of this article, you want the Silverlight.js file in the Resources folder.

The HTML file

So that everyone begins the same, let me supply a base HTML file for the starter page I’ll use in this article (Listing 1).

If you save the code for Listing 1 to a file with an .htm or .html extension, either drag that file to a browser window or double-click the file in an Explorer window. You should see the browser window of your choice open and the text, "Hello World".

Adding Silverlight

To add Silverlight to this page, you need to do four things:

  • Add a link to Silverlight.js.
  • Add a DIV tag for the ActiveX control.
  • Instantiate a control into the DIV tag.
  • Create an XML file to direct the control.

The first three are fairly simple and are highlighted in color in Listing 2.

The code shown in Listing 2 is the template that I use for pages. I tweak it from here, but for purposes of this article, you can use this code. I will explain the tweaks below.

"Add a link to Silverlight.js" is in red, and is simply a link to the location of the Silverlight.js file mentioned in the downloaded resources. I have a js folder containing any external JavaScript files, and that’s where I put Silverlight.js, hence the js/Silverlight.js reference.

"Add a DIV tag for the ActiveX control" is next and in green. This is a standard DIV tag declaration with an ID label of your choice. I chose a background of white just because that’s the normal color I use for article pages. Next is a bit of JavaScript that declares a variable you’ll be using in a minute. The variable is the document element defined by the ID label.

If you have multiple canvases on your page, you will need multiple unique DIV tag IDs and unique variable names.

"Instantiate a control into the DIV tag" is the most complex part of the HTML side of this process and is in blue. Remember this is a template and you can therefore just drop it into place. You can do this instantiation in a couple different ways. The way I am explaining is the most complex, but gives you the most control. The QuickStart you downloaded with the SDK advocates the use of an external JavaScript module. If you have multiple Silverlight canvases you will end up with either multiple external files or multiple sections in one external file. I’ve chosen to keep this all inside the HTML file that it’s associated with. The approach to take in this section depends on how you plan to present and use your site.

The following is a breakout explanation of each section in createObjectEx as used in this article. Changes to the files as advocated by the QuickStart will have similar sections.

source: ‘xaml/HelloWorld.xml’

The source defines the location of the XAML file controlling the ActiveX control. I have placed this in a subfolder named XAML and have given it the file extension .xml. Multiple canvas applications would need multiple XAML files.

parentElement:pe1

The parentElement is a reference to the variable that the DIV tag defines for the control. Multiple canvas applications would need multiple DIV tags and, therefore, unique parentElements.

id:’Ag1’

This ID is a unique ID for the object.

width:’300’

The width of the canvas-depends upon the project.

height:’300’

The height of the canvas-depends upon the project.

background:’#FFFFFFFF’

The color of the canvas itself, including the opacity. In this case, the opacity is 100% and the color is white.

isWindowless:’true’

If this is true and the background color of the canvas has an alpha value, Silverlight blends with the HTML page.

framerate:’24’

Framerate is the maximum number of frames to display per second. 24 is the default and the maximum is 64.

version:’1.0’

The version required to run the page.

events

The default values are listed.

I’ve glossed over “events” and shown the default for “framerate”. The documentation details other parameters in CreateObjectEx that you might want to look at after you get more involved with Silverlight. For the time being, what is here will get the job done.

&

By: Dave Campbell

Currently employed by Minerva Engineering of Tempe, Arizona, Dave Campbell is a .NET developer with over 30 years experience in all segments of the software industry. Dave is a Microsoft MVP: Visual Developer-Client Application Development.

Having spent the majority of his time working on UI issues over the years, Silverlight is a good match to Dave’s skill set and Silverlight has become an all-encompassing “free time” exercise at WynApse.com and SilverlightCream.com.

dave@wynapse.com

Fast Facts

Everyone building Web pages is familiar with HTML and, like it or not, you are familiar with JavaScript as well. Those two pieces of knowledge is all the foundation you need to get started with Silverlight 1.0 and this article will show you how to accomplish that transition.



Listing 1: The base HTML file for prior to inserting Silverlight
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<html>
<head>
   <title>
      First Silverlight Page
   </title>
</head>

<body>
<br>
Hello World
<br>
</body>
</html>


Listing 2: The base HTML with Silverlight additions
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<html>
<head>
   <title>
      First Silverlight Page
   </title>
   <script src="js/Silverlight.js" type="text/javascript">
   </script>

</head>

<body>
<br>
Hello World
<br>
<div id="Ag1Host" style="background:#FFFFFF">     
   <script type="text/javascript">
      var pe1 = document.getElementById("Ag1Host");
   </script>  
</div>

<script>    
Silverlight.createObjectEx(
  {source: 'xaml/HelloWorld.xml', 
   parentElement:pe1, 
   id:'Ag1', 
   properties:
   {width:'300', 
    height:'300', 
    background:'#FFFFFFFF', 
    isWindowless:'true', 
    framerate:'24', 
    version:'0.90.0'}, 
   events:
   {onError:null, 
    onLoad:null}, 
   context:null});
</script>

</body>
</html>


Article Pages:  1  2 3 4 - Next Page: 'XAML' >>

Page 1: Catching the (Silver) Light
Page 2: XAML
Page 3: Part 2
Page 4: Desired Solution

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.2 out of 5

121 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      Sharepoint TechCon

 

SSWUG