Windows Store Apps For Absolute Beginners With C#

Here, in this application, I will show you how to develop Windows store apps in Windows 8 and how to test them using the local machine and a simulator. To create a project, open your Visual Studio and create a new project of the type shown below:
 
 

Choose a blank app(XAML) and press the OK button and it will add the following things in the Solution Explorer.

 

Here, I am briefly describing everything added in this Solution Explorer.
 
App.Xaml

When your Application starts,  first the App.xaml file is loaded and it contains all the app-level resources and settings. This file is like Global.asax file in ASP.NET, which is first to run. The App.Xaml will look as shown below:
  1. <Application  
  2. x:Class="Myapp.App"  
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  5. xmlns:local="using:Myapp">  
  6.   
  7. </Application>  
Assets- This is a folder which mainly contains the splash screen and a different logo used in the Application.

MainPage.xaml- It is similar to a .aspx page or a view in ASP.NET, where you have to design your UI. It uses XAML to design the UI.
 
MainPage.xaml.cs- This is similar to aspx.cs page in ASP.NET, where the main logic will be written.
 
Myapp_TemporaryKey.pfx- This is the certificate for your Windows app. When you first create a new project in Visual Studio, it will create a new test certificate automatically.
 
Now, I designed my UI, as shown below:

 
 
Here, the source code(XAML) for this design is as follows:
  1. <Grid Background="BlanchedAlmond" Width="963" Height="396" >  
  2.      <StackPanel Margin="151,99,0,0">  
  3.          <TextBlock Text=" Windows Apps Tutorial Part-1" FontSize="36" Foreground="Red" Margin="0,0,24,0"  />  
  4.          <StackPanel Orientation="Horizontal" Margin="0,20,0,20">  
  5.              <TextBox Name="txt_name" Width="421" HorizontalAlignment="Left" Height="46" FontSize="24" Background="DeepPink"/>  
  6.              <Button Content="READ" Height="50" Background="Black" Click="Button_Click"/>  
  7.          </StackPanel>  
  8.           
  9.      </StackPanel>  
  10.  </Grid>  
  11. ;/Page>  
On the button, click and write the code, given below, to open a message box to show the text entered in the textbox by the user. 
  1. private void Button_Click(object sender, RoutedEventArgs e)  
  2.         {  
  3.   
  4.             //Creating instance for the MessageDialog Class    
  5.   
  6.             MessageDialog msgbox = new MessageDialog("Good Morning" + " "+ txt_name.Text);  
  7.               
  8.              msgbox.ShowAsync();   
  9.   
  10.         }  
W can check in two ways i.e- Local Device and in Simulator. Let's check the result in Local Device and Simulator. Press F5 to run the project and check the output.



Enter a name in the textbox and click the Read button.

 

Click the Read button and it will show the message box, as depicted below:

 

Here, the output comes as expected.

Let's check with the simulator.

Choose the simulator option as follows.

 
 
Now, run the project.

 
 
Now, check the result by putting a name on the textbox.

In this way, we can check the app in the simulator. This tutorial is  basic, as far as Windows store apps are concerned. I hope  this will help you.

Next Recommended Readings