Thursday, August 7, 2008

How to create a Silverlight Application

Technology

Technology Used:

  1. Microsoft Silverlight 2.0 Beta 2
  2. Microsoft Silverlight 2.0 SDK Beta 2
  3. Microsoft Silverlight 2.0 Tools Beta 2 for Visual Studio 2008
  4. Microsoft Expression Blend 2.5 June 2008 Preview
  5. Microsoft Visual Studio 2008
  6. IIS 7

Implementation

How to create a Silverlight Application

Silverlight Application can be created in both Visual Studio 2008 and Expression Blend. It can be opened in both programs too.

Visual Studio 2008

To create in VS 2008,

  1. Run Visual Studio 2008 (if Win Vista, run as Administrator)
  2. Go to File -> New and click on Project.
  3. Select Silverlight at the Project Type panel, and then select Silverlight Application at the Template List panel.
  4. Noticed that it prompts you a new window with the title “Add a Silverlight Application”, in this window you may select a default settings and it will create a Website Project and a Silverlight Application Project.
  5. Build the solution, and you will notice that a file with the extension .xap is created in the ClientBin folder under the website project.clip_image002
  6. You can find 2 XAML files under Silverlight Application project. App.xaml is a XAML file that stores application level resources while Page.xaml is a main page that stores the resources and page elements at page level. To View the Page.xaml file, you will see:-
<UserControl x:Class="SilverlightApplication6.Page"


    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 


    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 


    Width="400" Height="300">


    <Grid x:Name="LayoutRoot" Background="White">


  </Grid>


</UserControl>







Expression Blend



To create in Expression Blend,




  1. Run Expression Blend 2.5 (if Win Vista, run as Administrator.


  2. Click on New Project on the start-up menu.


  3. You will see 4 options, WPF Application (.exe), WPF Control Library, Silverlight 1 Site, and Silverlight 2 Application. You need to select Silverlight 2 Application.


  4. After it is completed, you will see the same file structure as in Visual Studio 2008 but without the website project. If you build and debug it, it will dynamically generate a test page to display the result.







2 comments:

wpfgirl said...

i have a question, i have iis installed and i created a silverlight app and the hosting works on my machine. so how do i open the webpage that i created w/ silverlight app? do i just have to expose the html or the aspx file? i did and it will say 'you are not authorized to view this page' althought i can view our webpages that are hosted on my pc. thanks... (i am quite new to silverlight although i already know some wpf)

Chris Par said...

Dear WPFGirl,

You are right as you need to use Silverlight/Object control to bind your Silverlight component into your aspx page.

Properly if you are facing authorization issue, then it might be the problem with your IIS/ASP.net setting on Authentication/Authorization.

Just make sure you have done this:-

http://chrispar.blogspot.com/2008/08/how-to-integrate-silverlight-component.html (bind your component to aspx page)

and

http://chrispar.blogspot.com/2008/08/how-to-deploy-silverlight-component-on.html (configure IIS to accept silverlight extension)

Hope it helps.

You may send an email to howkuang_par[at]hotmail.com to provide me more information so that I can look into it.

Possible Causes:-
1.) IIS Features
2.) Web.config

Recommended Steps to create a workable prototype:-
1.) Configure your IIS to accept silverlight extension.
2.) Create a silverlight application that compile successfully before deploy.
3.) create a asp.net test project to integrate with your component and try to compile it successfully before deploy.
4.) In VS, right click on your solution and publish it at IIS.
5.) In IIS, create a sample page and view it in browser and make sure it works.
6.) then run your aspx page that contains silverlight component.