Wednesday, June 9, 2010

Getting started silverlight

  • Open Visual Studio and Click File->New Project… And Select Silverlight Application in Silverlight Templates. You can give a name to the project say MyFirstApplication and click OK.Add new project
  • This is to select whether you need to add a web application in the solution to host the silverlight file(xap). This is optional depending upon your requirement. This is similar to adding projects to a solution.
Host silverlight in a new project
        • Drag and drop a Button and TextBlock control from the ToolBox in MainPage.xaml. You may adjust the width of TextBlock. Then double click the button to go to the ‘button1_Click’ event in the code file(MainPage.xaml.cs).  You may be able to see other available events for the control in the Events tab in Properties window. Double click a event to go to the particular event.
Add the code in the MainPage.xaml.csType the code below in the button1_Click event assuming Button name is ‘button1’ and TextBox name is textBlock1
private void button1_Click(object sender, RoutedEventArgs e)
{
    textBlock1.Text = "Hello, Welcome to silverlight";
}
  • Press F5 to start debugging the silverlight application.
Press F5 to start debugging the application

Click here to download the sample file

Share it Facebook  Twitter

No comments:

Post a Comment