Visual Studio 2012

Content "filtered", Please subscribe for FULL access.

Chapter 3 : Visual Studio 2012

Introduction to Visual Studio 2012 arrow_upward

  • Windows Phone programming is done using a tool called Visual Studio.
  • Visual Studio provides an environment where developers can edit, build and run programs.
  • It provides a debugging solution.
  • It provides many common UI controls.
  • Developers write a set of instructions in a high level language (VC#).
  • The compiler takes the high level instructions and converts them into lower level instructions (for execution on the computer).

  • The .NET SDK arrow_upward

  • Installing the .NET framework provides a command line compiler which can take C# source files and convert them into executable files.

  • A Simple Visual Studio Project arrow_upward

  • A project is a container for a set of program files and resources.
  • The simplest possible project would be one containing a single program file.
  • We can open new project by using the File>New>Project command to open up the New Project dialogue.
  • The New Project dialogue shows us all the possible project templates that are supplied with Visual Studio.
  • To create the simplest possible project we need to open template for Visual C# Windows Phone App, Give it name of your choice and locate the solution wherever you want to.
  • The solution of a build contains following files by default:
    • App.xaml
    • MainPage.xaml,
    • MainPage.xaml.cs
    • SplashScreenImage,
    • Background,ApplicationIcon
  • When we create a Silverlight project using Visual Studio, it creates a default XAML file called "MainPage.xaml" .
  • This is just a dummy start page created by Visual Studio, and it does not contain any visible UI elements. The default contents of the MainPage.xaml file looks like this:
  • App.xaml is a file used by Silverlight applications to declare shared resources like brushes, various style objects, templates etc.
    • Also, the code-behind file of App.xaml.cs is used to handle global application level events like Application_Startup, Application_Exit, and Application_UnhandledException. App class is the starting execution point for a program.
  • When Visual Studio creates the App.xaml file automatically, it creates a few event handlers with some default code.
  • For different resolutions we require different dimensions of SplashScreenImage.png, a single splash of 480 x 800 can be used for all possible resolutions.

  • Resolution

    Dimensions in pixels


    480 × 800


    768 × 1,280


    720 x× 1,280

    Making a Basic Windows phone Program arrow_upward

  • So far we have created a template app which is ready to run, now we add Controls to our app.
  • In Visual Studio, open the controls Toolbox by clicking View | Toolbox
  • Drag and drop a Button, TextBlock and a TextBox from the Toolbox.
  • Double click the Button to add an OnClick event handler to the button.
  • Visual Studio adds the button1_Click event handler to the MainPage.xaml.cs file and opens the editor for you to add code.
  • In this scenario, we add code to copy the contents of the TextBox’s Text property to the TextBlock Text property.
  • Adjust your control and your MainPage.xaml will look like:
  • <Grid x:Name="LayoutRoot" Background="Transparent">
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            <StackPanel Grid.Row="0" Margin="12,17,0,28">
                <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" Background="Gray">
                <TextBlock x:Name="textBlock1" Height="100" Width="auto" HorizontalAlignment="Center"  Text="TextBlock" FontSize="55" Margin="0,-200,0,0" />
                <TextBox x:Name="textBox1" Height="100" Width="250" Background="AntiqueWhite"   />
                <Button Height="100" Width="250" Margin="0,200,0,0" Content="Button" Click="Button_Click_1" />
  • Go to MainPage.xaml.cs In button1_Click method, add the following code:
  •    private void Button_Click_1(object sender, RoutedEventArgs e)
               textBlock1.Text = textBox1.Text;
  • In the MainPage constructor method, add the following code immediately before the closing brace. This will initialize the TextBox and TextBlock.
  • C#:

    textBox1.Text = "Hello World";
    textBlock1.Text = "";
  • Click File | Save All to save your work.
  • Select Emulator on standard toolbar Run the project by pressing Run button on standard toolbar or Press F5.
  • Output will be shown as below:
  • On tapping the button we will get following output:

  • Namespaces arrow_upward

  • The namespaces are a logical way of grouping items together.

  • Library Assemblies arrow_upward

  • When we create a new project we can create a library project also.
  • The classes in the assembly will contain a Main method.
  • A library assembly compiles to a file with the language extension Dynamic Link Library (.dll).
  • The dynamic link part means that the library classes are loaded dynamically when the program runs.
  • When the program refers to a method in a class in the library that class will be loaded into memory.
  • The compiler will convert the method into machine code.

  • System Libraries and References arrow_upward

  • A program running under .NET makes use of system resources (as it runs).
  • The methods are held in the system libraries, which are dll files.
  • An assembly file contains references to the library files that it works.
  • This list of references is maintained in Visual Studio via the Solution Explorer pane.

  • Creating a Multi-Project Solution arrow_upward

  • We can pick up any of the project templates and make a new project which is held as part of the solution.
  • A new library project called “Display Library”.
  • This will compile to produce a dll file which will be stored in the binary folder for the new project.

  • Windows Phone Solutions arrow_upward

  • There are essentially two kinds of Windows Phone solutions that can be created using Visual Studio.
  • Those are as follow:
    • Silverlight application
    • XNA application

    Silverlight Windows Phone Project arrow_upward

  • A Windows Phone Silverlight solution contains the MainPage.xaml.
  • Silverlight VC# will be added to this project as code behind file.

  • XNA Windows Phone Project arrow_upward

  • The XNA framework was developed for writing games.
  • It also provides comprehensive content management so that images, textures and sounds can be easily incorporated into a game.
  • When we make an XNA solution using the template supplied by Visual Studio we get two projects created.
    • One of these contains the executable code
    • The other holds all the content
  • If we want to make a game that runs on multiple platforms we just have to add new projects to the solution.

  • Thank You from Kimavi arrow_upward

  • Please email us at and help us improve this tutorial.

  • Mark as Complete => Receive a Certificate in Windows-Phone-Programming

    Kimavi Logo

    Terms and conditions, privacy and cookie policy

    Kimavi @ YouTube | Email Admin @ Kimavi | Visit TheCodex.Me

    Beautiful Educational Videos for School, College, Languages & Encyclopedia

    Learn Python with 500,000 students

    Created with Love