Applications Templates in Visual Studio


C# Applications in Visual Studio

Visual Studio supports the development of different types of applications such as Windows based client applications, web-based applications, services, and libraries. To help you get started, Visual Studio provides application templates that provide a structure for the different types of applications.

These templates:

  • Provide starter code that you can build on to quickly create functioning applications.
  • Include supporting components and controls that are relevant to the project type.
  • Configure the Visual Studio IDE to the type of application that you are developing.
  • Add references to any initial assemblies that this type of application usually requires.

Types of Templates

The following table describes some of the common application templates that you might use when you develop .NET Framework applications by using Visual Studio .

Template Description
Console Application Provides the environment settings, tools, project references, and starter code to develop an application that runs in a command-line interface. This type of application is considered lightweight because there is no graphical user interface.
Windows Forms Application Provides the environment settings, tools, project references, and starter code to build a graphical Windows Forms application.
WPF Application Provides the environment settings, tools, project references, and starter code to build a rich graphical Windows application. A WPF application enables you to create the next generation of Windows applications, with much more control over user interface design.
Windows Store Provides the environment settings, tools, project references, and starter code to build a rich graphical application targeted at the Windows 8 operating system. Windows Store applications enable you to reuse skills obtained from WPF development by using XAML and Visual C#, but also from web development by using HTML 5, CSS 3.0, and JavaScript.
Class Library Provides the environment settings, tools, and starter code to build a .dll assembly. You can use this type of file to store functionality that you might want to invoke from many other applications.
ASP.NET Web Application Provides the environment settings, tools, project references, and starter code to create a server-side, compiled ASP.NET web application.
ASP.NET MVC Application Provides the environment settings, tools, project references, and starter code to create a Model-View-Controller (MVC) Web application. An ASP.NET MVC web application differs from the standard ASP.NET web application in that the application architecture helps you separate the presentation layer, business logic layer, and data access layer.
WCF Service Application Provides the environment settings, tools, project references, and starter code to build Service Orientated Architecture (SOA) services.

Creating a .NET Framework Application

The application templates provided in Visual Studio enable you to start creating an application with minimal effort. You can then add your code and customize the project to meet your own requirements.

The following steps describe how to create a console application:

  1. Open Visual Studio.
  2. In Visual Studio, on the File menu, point to New, and then click Project.
  3. In the New Project dialog box, do the following:
  1. Expand Templates, Visual C#, and then click Windows.
  2. Click the Console Application template.
  3. In the Name box, specify a name for the project.
  4. In the Location box, specify the path where you want to save the project.
  1. Click OK.
  2. The Code Editor window now shows the default Program class, which contains the entry point method for the application.

The following code example shows the default Program class that Visual Studio provides when you use the Console Application template.


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    }
   }
 }

Overview of XAML

Extensible Application Markup Language (XAML) is an XML-based language that you can use to define your .NET application UIs. By declaring your UI in XAML as opposed to writing it in code makes your UI more portable and separates your UI from your application logic.

XAML uses elements and attributes to define controls and their properties in XML syntax. When you design a UI, you can use the toolbox and properties pane in Visual Studio to visually create the UI, you can use the XAML pane to declaratively create the UI, you can use Microsoft Expression Blend, or you can use other third-party tools. Using the XAML pane gives you finer grained control than dragging controls from the toolbox to the window.

The following example shows the XAML declaration for a combobox, checkbox, textbox, and button:

Defining Controls in XAML


    <Window x:Class="XAMLControlsExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Content="Button" HorizontalAlignment="Left" Margin="67,50,0,0" 
        VerticalAlignment="Top" Width="75"/>
        <CheckBox Content="CheckBox" HorizontalAlignment="Left" Margin="67,96,0,0" 
        VerticalAlignment="Top"/>
        <ComboBox HorizontalAlignment="Left" Margin="168,50,0,0" 
        VerticalAlignment="Top" Width="120"/>
        <TextBox HorizontalAlignment="Left" Height="23" Margin="168,94,0,0" 
        TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
    </Grid>
    </Window>

You can use XAML syntax to produce simple UIs as shown in the previous example or to create much more complex interfaces. The markup syntax provides the functionality to bind data to controls, to use gradients and textures, to use templates for application-wide formatting, and to bind events to controls in the window.

The toolbox in Visual Studio also includes container controls that you can use to position and size your controls appropriately regardless of how your users resize their application window.


PROMOTIONS