Advertisment

Creating Desktop apps with Silverlight

author-image
PCQ Bureau
New Update

Silverlight 3 Beta enables youto run and create applications for your

desktop, which means you can use them without Internet connectivity. You can

store and use Silverlight apps locally without having to download extra

plug-ins. Besides, Silverlight 3 based apps are able to detect Internet

connectivity and react intelligently like caching user data, etc. As these

applications run inside a secure sandbox environment with persistent isolated

storage, they are quite safe to use.

Advertisment

Direct Hit!

Applies To: Web Developers



USP: How to create desktop app with
Silverlight



Primary Link:
www.silverlight.com




Keywords:
Silverliht 3

Implementation



To build a Silverlight 3 based app, you need either Visual studio 2008 SP1 or
Visual Web Developer Express 2008 SP1. In this implementation, we have used the

latter. Now to add Silverlight 3 application building capability to this IDE,

download and install Silverlight 3 Beta Tools for Visual Studio from http://tinyurl.com/cgzacz.

This will install the runtime and Silverlight 3 Beta SDK. We have used C# as

programming language in this demo. Now start Visual Web Developer and create new

'Silverlight Application' project ('SilverlightApplication1'). You need a Web

page to host this application, therefore Visual Web Developer Express 2008

prompts either creation of test page or a complete ASP.NET project. We created

ASP.NET project named 'SilverlightApplication1.Web' in this implementation. From

the solution explore open two files 'MainPage.xaml' and 'MainPage.xaml.cs'.

These are two files that define structure and logic of a Silverlight

application. Here is the sample structure of 'MainPage.xaml' file:



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



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


Width="400" Height="300">














Storyboard.TargetProperty="Color" From="Gold" To="Silver" Duration="0:0:4" />





































Advertisment
To install Silverlight app

locally, simply right click on browser window and click on Install. As shown

above, one can add a shortcut to the desktop and Start Menu.

In this application, we have created a button click event 'Mouse_Clicked' and

storyboard named 'Storyboard1'. This application creates animation on left mouse

click. With this event, the Gold color in browser will change to Silver in four

seconds. Here is the sample code of 'MainPage.xaml.cs' file that simply

initiates animation :

using System.Windows.Media.Animation;



using System.Windows.Shapes;


namespace SilverlightApplication1


{


public partial class MainPage : UserControl


{


public MainPage()


{


InitializeComponent();


}


private void Mouse_Clicked(object sender, MouseEventArgs e)


{ Storyboard1.Begin(); }


}


}













Advertisment

So far, this application looks like any other Silverlight application. To

make this application run from your desktop, you need to change 'AppMainfest.xml'
file present under 'Properties' in solution explorer . Here is the content of

this 'AppMainfest.xml' file :

Here is thesame Silverlight app

running from your desktop in a window titled 'Silverli ght Animation -

localhost '. To remove it, right click and click 'Remove this application'.



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















ShortName="PCQuest out of Browser Silverlight Application"



Title="Silverlight Animation">


Simple anuimation














Here '' contains information like short name

that appears as name of shortcut, title that appears in the title bar, blurb for

more information, and optional icons for defining customized icons. When we run

this application, it runs in the default browser window. To make this

application run out of window, right click on browser window and click on

'Install PCQuest out of Browser Silverlight Application onto this computer'.

This action will install application on your computer and prompt user to add a

shortcut to desktop and Start Menu. Now close your browser and click on desktop

shortcut ('PCQuest out of Browser Silverlight Application — localhost'). This

will open same application out of browser locally and there is no need for

Internet connection. The moment you get connected to Internet, this application

goes back to the server to check for updates. The application will notify the

user if a newer version is available.

If you want to remove this application, simply right click on out of browser

window and click on 'Remove the application'. Silverlight 3 Beta also comes with

improved audio and HD video support, 3-D graphics and pixel shading effect, and

enhanced data



support.

Advertisment