Jumat, 02 Agustus 2013

Create a Simple WPF application

Windows Presentation Foundation (WPF) is a new graphical subsystem for rendering user interfaces in windows based application developed in Visual Studio. WPF is a next generation presentation system for building windows client applications. WPF should be very familiar if you have previously built applications with .NET Framework using ASP.NET and Windows Forms.

XAML is a declarative XML based language that is used for initializing structured values and objects. When used in WPF, XAML is used to describe visual user interfaces. WPF allows for the definition of both 2D and 3D objects, rotations, animations, and a variety of other effects and features.

These simple steps can be followed to create a new WPF application:
  1. Start Visual Studio "the version you have".
  2. From the menu bar go to File>>New>>Project. A dialog box will appear.
  3. From the drop down list you can select the framework in which you want to work. In the left side pane expand Visual C#, and then select Windows.

    Select new WPF application template as a new project
  4. There is a middle pane including a list of templates. Select WPF Application template.
  5. You can specify a name and location for the project in the Name and Location textbox respectively.
  6. Click OK and MainWindow of the new project will appear.

    The default UI environment of new WPF application
A new project has been created with some files like other project. A file named MainWindow.xaml is already open as in our above screenshot, it will be shown first when launching the application. App.xaml is central starting point, can be used to change the first window.

You can run the application now to see the empty window because our XAML code consists nothing to show. To show a simple message “My First WPF Application”, we have to write the following code in between the Grid panel.
<Grid>
<TextBlock Text="My First WPF Application"></TextBlock>
</Grid>

Run the application now and our message is displayed in the top left corner of the window. We have used a single Text property of the Text block and that is it.
WPF first message shown when run the application

Tidak ada komentar:

Posting Komentar