A day with .Net

My day to day experince in .net

Hello World Windows 8 Metro App

Posted by vivekcek on September 3, 2012

Download Source Code: http://sdrv.ms/NQmKeD

Today I am going to show you how to create a simple Hello World metro app. Our Hello Word app contain a text box and a button. If we enter some text in the textbox and press submit button that text will be shown in our app.

Software’s You Need.
————————————-

. Windows 8 beta or release preview
. Visual Studio 2012 Express for Windows 8.

Knowledge Need
——————————-

. XAML,C#, Visual Studio.

1. Open the Visual Studio 2012.

2. Create a new blank project. Give some name ‘MyApp’.

3. Go to solution explorer and delete MainPage.xaml.

4. Now select and right click on the MyApp project. From the context menu select Add -> New Item

5. Add a basic page. Give name as MainPage.xaml.

6. Now in the xaml mark up of MainPage just above VisualStateManger and in the Root Grid Copy the xaml mark up code given below.

<StackPanel Grid.Row="1" Margin="100,10,0,-1" >
            <TextBlock Text="Enter Your Name"/>
            <StackPanel Orientation="Horizontal" Margin="0,20,0,0">
                <TextBox x:Name="txtInput" Width="200" HorizontalAlignment="Left"></TextBox>
                <Button x:Name="btnSubmit" Content="Submit" Margin="5,0,0,0" ></Button>
            </StackPanel>
            <TextBlock x:Name="txtOutput"></TextBlock>
        </StackPanel>

7. This xaml mark up create a textbox and button with some textblock for display data.

8. Now we need to generate a click event for out submit button. We need to use the property window to generate click event.

9. Add the below code in the event handler generated in MainPage.xaml.cs.

 private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            txtOutput.Text = "Hai " + txtInput.Text;
        }

10. Final Output

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s