Building First WPF Application

In this article we will become familiar with WPF using a simple example to understand how to create a WPF project, as well as the tools, regardless of the WPF project. If you've ever done a project in C# or any other language in a Visual Studio then the steps below are all too familiar to you. As for the first case, you become familiar with the Visual Studio WPF and hopefully this article will more or less have the most value for you.

1. Create a new project

To create your menu: "File" -> "New" -> "Project..." or can also use the shortcut Ctrl + Shift + N. Then the dialog box will be shown as below. At the left is a list with the C# language -> Windows Application. In the middle of our list select WPF Application WPF project to create a new one. You can change the folder name and hosting for the project Name and Location below. Then OK to start.

001-the first-wpf- application-microsofttech.net.jpg

In the next step the interface will appear as shown below. I se a MainWindow object between the screens, this is the main form in our program. As we can see this form does not have a border like the Form as usual in C # Winform Application applications. The omitted boder shows that the application is for the web environment, if you execute the application then it does not require the a border and the border is omitted, also makes the Windows-based application simpler. I actually nearly did not manipulate anything on this border. Another point is that the form always correctly aligns the screen instead of in the upper left as for a normal Winform application.

2. Dialog box, the tools we need to consider first

Toobox: Where no controls for your application. The control is similar to a winform application, in addition there are several additional new controls with better features and greater customization capabilities. We'll determine what in turn plays in a later post.
Properties: It sets the properties for the control, changes the shape size, color ... and sets up events for controls.

Explorer Solution: Here we see the components and resources within the project.

An interesting feature of WPF is the zoom slider to make the form he larger, that makes it easy to zoom up to the control layout more precisely, if the form is too big then it can be shrunk.

Beneath that it is possible to change between the two work modes design and XAML code. Or if your screen is big enough then you can select the display mode for both frameworks simultaneously.

002-the first-wpf- application-microsofttech.net.jpg

The following is a detailed picture of the 3 Box tools: Toolbox, Solution Explorer and Properties.

003-the first-wpf- application-microsofttech.net.jpg

3. Start the first project

As in a Winform application you can add controls directly through the Toolbox drag and drop. Also you can add more controls by writing the XAML code. This is new and is also strong in WPF. You can quickly create one control and set the properties quickly using a short code number.

In the example below we create 1 button and 1 in the ComboBox button. This is quite strange, is it not? A Winform application does not allow creation of such a nested control, but in WPF you can absolutely, not only that but also many of interesting things are waiting for you to discover.

004-the first-wpf- application-microsofttech.net.jpg

Compile and run the application.

005-the first-wpf- application-microsofttech.net.jpg

From my Site: http://microsofttech.net/lap-trinh/xay-dung-ung-dung-dau-tien-voi-wpf.html

Up Next
    Ebook Download
    View all
    Learn
    View all