Nov 15

These tutorials are helping explain some of the core programming concepts of Silverlight.

We’ll start our SilverlightSample application by selecting the File -> New Project menu item within Visual Studio 2008 or Visual Web Developer 2008 Express (which is free) and use the New Project dialog to create a SilverlightSample (note: you will need to download and install the Silverlight Tools for VS 2008 release to get this support).

Alomohora - Silverlight - Creating Hello World1

We’ll name the project SilverlightSample. When we click the OK button Visual Studio will prompt us with an additional dialog that allows us to choose whether we want to create just a Silverlight Application project, or optionally also add a server-side ASP.NET Web project to our solution to host the Silverlight Application within. For this sample we’ll choose to add an ASP.NET Web Application project to the solution as well and name it SilverlightSample.Web.

Alomohora - Silverlight - Creating Hello World2

When we click OK Visual Studio will create a solution for us that have both a Silverlight client application and an ASP.NET web server application in it.

Alomohora - Silverlight - Creating Hello World3

Right now our SilverlightSample application doesn’t do anything, and when it is run it brings up an empty page. We can change this by opening up the Page.xaml file in the project and adding some content to it.

Alomohora - Silverlight - Creating Hello World4

We’ll begin by changing the background of the grid and by declaring a Button control within it. We’ll give the button an x:Name attribute value of MyButton – which will allow us to programmatically reference it within our code-behind class. We’ll also set its Content, Width and Height properties.

Alomohora - Silverlight - Creating Hello World5

When we run the application our button will then show up in the middle of the page with Push Me content text like below.

Alomohora - Silverlight - Creating Hello World6

To add behavior to our button we can add a Click event handler to it. We can do this in source view by typing the event name.

Alomohora - Silverlight - Creating Hello World7

This will then prompt us for the event handler in our code-behind class to use.

Alomohora - Silverlight - Creating Hello World8

We can then either type a new event handler method name to use, or optionally just press the enter key to name the event handler method using the default naming convention.

Alomohora - Silverlight - Creating Hello World9

This is full code:

<UserControl x:Class=”SilverlightSample.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”>

     <Button x:Name=”MyButton” Content=”Push Me!” Width=”100″ Height=”50″ Click=”MyButton_Click”></Button>

   </Grid>

</UserControl>

VS will then automatically create a stub event handler implementation in our code-behind class file. We can use this event handler to update the Button’s content with a new message when it is clicked.

Alomohora - Silverlight - Creating Hello World10

This is full code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

namespace SilverlightSample

{

   public partial class Page : UserControl

   {

      public Page()

      {

         InitializeComponent();

      }

 

      private void MyButton_Click(object sender, RoutedEventArgs e)

      {

         MyButton.Content = “Pushed”;

      }

   }

}

After making the change above us can re-run the application and push the button again, and now its content is updated with a Pushed! Message.

Install Microsoft Silverlight

Download source code

Incoming search terms for the article:

??? ?????????? zeoslib ?? delphi xe, componente zeos para delphi xe2, creating hello world in silverlight, delphi xe2 zeosdbo, instalar zeoslib en delphi xe2, Well start our application by selecting the File->New Project menu item within Visual Studio 2008 or Visual Web Developer 2008 Express (which is free) and use the New Project dialog to create a Silverlight Application (note: you will need to download a, zeos xe2, zeoslib xe2

Leave a Reply

Features Stats Integration Plugin developed by YD