Developer's Academy: Famous Hello World App !!

Monday, 1 September 2014

Famous Hello World App !!

Step: 1 Create a new Project

1. Launch Visual Studio 2013

2. Select File > New Project

3. In the left pane, expand Installed > Templates, then expand Visual C# and pick the Windows Store template type. The dialog's centre pane displays a list of project templates for Windows Store apps.




4. In the centre pane, select the Blank App (Windows Phone Silverlight) template.

5. In the Name text box, enter "HelloWorld".

6. Click OK to create the project.

Visual Studio creates your project and displays it in the Solution Explorer.



Step: 2 Start the App

Run the Application using "Emulator 8.1 WVGA 4 inch 512MB"


At this point, you created a very simple app. If you want to see what it looks like, press F5 to build, deploy, and launch your app in debugging mode. A default splash screen appears first. The splash screen is defined by an image and a background color.



Step: 3 Modify start page

1. Double Click on App.Xaml from the right pane.

2. Remove the existing code and add the following lines of code:

<StackPanel Grid.Row="1">
  <TextBlock Text="What's your name?" FontSize="40"/>
    <StackPanel Orientation="Horizontal">
      <TextBox x:Name="nameInput" Width="300"/>
      <Button Content="Say &quot;Hello&quot;"/>
    </StackPanel>
  <TextBlock x:Name="greetingOutput"/>
</StackPanel>



Step: 4 Create an event handler

XAML elements can send messages when certain events occur. These event messages give you the opportunity to take some action in response to the event. You put your code to respond to the event in an event handler method. One of the most common events in many apps is a user clicking a Button.

Let's create an event handler for your button's Click event. The event handler will get the user's name from the nameInput TextBox control and use it to output a greeting to the greetingOutput TextBlock.

Add an Event Handler

1. In XAML or design view, select the "Say Hello" Button that you added to MainPage.xaml.

2. In the Properties Window, click the Events button.

3. Find the Click event at the top of the event list. In the text box for the event, type the name of the function that handles the Click event. For this example, type "Button_Click".


4. Press Enter. The event handler method is created and opened in the code editor so you can add code that's executed when the event occurs.

5. Add code to the event handler that you created in the code behind page. In the event handler, retrieve the user's name from the nameInput TextBox control and use it to create a greeting. Use the greetingOutput.

private void Button_Click(object sender, RoutedEventArgs e)
{
greetingOutput.Text = "Hello, " + nameInput.Text + "!";
}

6. Run the App on emulator.



No comments:

Post a Comment