Skip to main content

Cloud

Silverlight Managed Code Development – The Basics (Part 1 of 3)

I’m writing a three part blog which concentrates on developing some simple Silverlight Alpha 1.1 applications using managed c# code.

The first application will just be an introduction Hello World to get you familiar with the environment. The other two applications will concentrate on using web services to get data. The first web service application will be a simple “Hello World” web service which will retrieve the "data" from a web service on the same domain. And since Silverlight fits well in the Web 2.0 environment, the second web service application will be a simple photo gallery mashup application which retrieves data using a cross-domain web service.

To get started with Silverlight Alpha 1.1 application development go to http://silverlight.net/GetStarted and download all the needed tools.

1) Runtime Silverlight Alpha 1.1

2) Microsoft ASP.NET Futures (May 2007)

3) Microsoft Visual Studio codename “Orcas” Beta 1

4) Microsoft Silverlight Tools Alpha for Visual Studio codename "Orcas" Beta 1

5) Expression Blend 2 May Preview (there are other Design tools you might want to download but for what I’m showing you don’t need them.)

6) A good idea will be to download the SDK’s but again for what I’m showing you don’t need them.

Now that you have all the tools downloaded and installed we can get started creating our first Silverlight application. By the way, I installed my entire environment in a virtual machine, of course, and I took a snapshot of it before I got started.

The first thing we will do is create a Silvelight project in Visual Studio.

I’m calling my solution FirstWebService (yeah, I know I’m creative).

Once the solution is created you will see the Silverlight project similar to the figure below.

The Page.xaml is your root presentation layer. In my demonstration I’m going to be building all the presentation in this file. I’m not going to be creating additional controls nor will I use other controls.

In the solution you also see the TestPage.html which will load the XAML when you run the project. You can try that now, but you will not see much. So before we do that, let’s do something simple. Let’s change the background color of our canvas in Expression Blend. Right click on the Page.xaml file. You will see an option to open the file in Expression Blend.

Once Expression Blend is up, you will see that it uses the same solution as Visual Studio.

To change the canvas background color, click on the canvas itself and then on the right hand side applets click on Properties. From there you will see how you can change the color of the background.

Once you save the changes and go back to Visual Studio, Visual Studio will ask you if you want to reload the XAML file since it was changed by another application. Of course say yes.

Now if you run the application (F5 in Visual Studio) you will see your very first Silverlight application.

Now, go back to Expression Blend and add a text block. If you made your canvas background color black as I have, make sure you change your text block foreground color to something other than the default black.

If you run your application again, you will see your new text block.

In Visual Studio open your XAML file if it is not open and add the x:Name attribute to the text block so we can reference this text block from our code behind.

Now if you go to the code behind class, you will be able to change the text (and other properties) of the text block. Note: Make sure that you actually save the XAML file before switching to the code behind class. If you don’t, you will not see a reference to the text block in your code behind. I’m not sure if this is the way it is going to work for good, or if this is just part of the Alpha feature list.

So now when you run your application you will see the changes you have made.

That’s all folks for the first blog. You now have a first look at creating a simple Silverlight application using managed code.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

PointBridge Blogs

More from this Author

Follow Us