Creating Hello World application with Silverlight 3.0 with Visual Studio 2010

No.of Views1142
Bookmarked1 times
Downloads 
Votes0
By  jalpesh   On  16 May 2010 01:05:33
Tag : Silver Light and XAML , Applications
Silvelight is latest buzz in Microsoft.NET Technologies. Silverlight enable us to create rich user interface for the web based application
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Silvelight is latest buzz in Microsoft.NET Technologies. Silverlight enable us to create rich user interface for the web based application. Let create a simple application to understand how Silverlight application works.

We will start creating application with file menu –> New Project –>Silverlight application a dialog for silverlight application will open like following. 

Image Loading

Once you create a Silverlight application a new dialog will open to create a website which will host Silvelight application like following. 

Image Loading

This website are used for hosting Silvelight application. Please note that Silverlight application can also run with simple html file also. After clicking on Ok it will create a simple project like following in solution explorer. 

Image Loading

Now let's Create a simple button and on clicking on that button will print “Hello World” on screen.With Silvelight used Microsoft new UI Language called XAML which used to define the object in the SilverLight.

Once we create a silvelight application which will create a MainPage.xaml and MainPage.xaml.cs file for the same. It will create by default XAML like following. 

<UserControl x:Class="MySilverLight.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

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

</Grid>
</UserControl>

 

Here grid will be act as container like as we are using content pane in our asp.net application. Which can host the another objects like button text and other objects. Now I am creating a simple hello world button via adding following xml between <Grid> and </Grid> tag.

<Button x:Name="HelloWorldButton" Content="Push to print Hello World on Screen " Height="25" Width="250"></Button> 

Here x:name is name of button and content is text that will display on button,width will specify width of button and height will specify height of button. It will create a simple button like following in the design layout of silverlight application as following. 

Image Loading

Now let add a text block object which will print the Hello world text on the screen after clicking button with following XAML.

<TextBlock x:Name="Mytextbox" Text="Print Text" Height="25" Margin="75,197,92,78"></TextBlock>

Which will create a text block just below the button like following. Here margin will define the margin from four side just like html. Text block will behave just like label in asp.net application 

Image Loading

After that Let’s add a add a click event to button via modifying existing XAML like following .

<Button x:Name="HelloWorldButton" Content="Push to print Hello World on Screen " Height="25px" Width="250px" Click="HelloWorldButton_Click" ></Button> 

It will create a click handler for the button we have added after then we can add code to print Hello World!! to event handler we have just create like following.

private void HelloWorldButton_Click(object sender, RoutedEventArgs e)
{
   Mytextbox.Text = "Hello World!!!";
}

Now compile and run the application it will open a browser and once you click the button it will print a hello world!! text like following.
 

Image Loading

Enjoy the silverLight with Visual Studio 2010.

 
Sign Up to vote for this article
 
About Author
 
jalpesh
Occupation-Software Engineer
Company-DotNetJaps
Member Type-Expert
Location-India
Joined date-08 May 2010
Home Page-http://www.dotnetjalps.com
Blog Page-http://www.dotnetjalps.com
I am jalpesh vadgamaa an Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having experience of five year in Microsoft .NET Technology.I am working as Project Leader in Mid Size company.My work area comprises of Enterprise Level projects using ASP.NET and other Microsoft .NET Technologies.Please feel free to contact me for any queries via posting comments on my blog I will try to reply as early as possible.
 
 
Other popularSectionarticles
    Performance is a vital part for any application possibly more important for web based app.With wizard based approach of RIA service generally we tends to comprise all entities, exposing to the client and also allowing the DomainService to go for everything from the database. Not only this approach takes a toll on security, but also it loads the middle tier unreasonably. So this post is about few tips using which we can improve the performance. Well mostly we will cover the Pagination, Limiting
    Published Date : 10/Apr/2011
    My earlier post was about the basic CRUD operations on entities with relation .We had discussed about creating simple association and querying as well as Invoking CRUD operation onto them.As i have mentioned there ,here in this article we will have an in-depth look into Presentation Model and its mode of handling related multiple entities.
    Published Date : 10/Mar/2011
    This article will demonstrate how to build a traditional master page style application in Silverlight.
    Published Date : 16/Feb/2010
    In the previous lesson we talked about COM automation support introduced in Silverlight 4 and we said that COM automation is available only for Silverlight OOB (Out-of-Browser) applications that have Elevated Trust, and that’s one of the security restrictions imposed by Silverlight. Today, we’re going to talk about COM automation in more details and give few Silverlight examples that make use of this great feature.
    Published Date : 31/Mar/2011
    In April 2010 Silverlight 4 was released to the world with one of its great features ever, COM-automation support, that allows you to create cutting-edge applications that do everything you can imagine.
    Published Date : 27/Mar/2011
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top