C# WPF Tutorial – Basic Understanding

0
783
C# WPF Tutorial - Basic Understanding

C# WPF app development is used at a large scale in the world. Almost 90% of offline POS and desktop software are based on WPF & JAVA. But the WPF has more share in the market compared to JAVA.

You need to have the latest Visual Studio so you can get the latest features to work with. But WPF is supported in all VS versions. If you already have a Visual Studio then it’s great, else you can download it from here.

Let’s open Visual Studio and Click on “Create a new project”

C# WPF Tutorial - Basic Understanding - Visual Studio Create new project

New window prompt in which much more information appears, don’t worry about that. You just need to search for WPF .NET because this is what you need to get started, if you select simple WPF or WPF Core, then the whole development gets changed.

We will get started with the basics and move on to the most advanced version soon. But as a beginner just select that and start setup or project.

C# WPF Tutorial - Basic Understanding - Visual Studio Create new project setup

After this configuration screen appears in which you have to define essential information of your application. In the following image, you can see the name, location of the project, solution name, framework (technology) and a checkbox which is already self-explained.

C# WPF Tutorial - Basic Understanding - Visual Studio Create new project setup configure

If you mark check true, then your solution and project remain in the same folder. But if you uncheck that then your solution will be in a separate folder and your project will be in a separate folder. For understanding, the solution is the main source of development of the application.

A solution can contain many projects (Apps), but a project can’t hold any solution. The solution is also the file of the visual studio which contain essential information about your project, if you delete the solution file then the visual studio will not able to process your whole application for further development.

Learn more about solutions and projects in Visual Studio from Microsoft.

Once we are done with the whole process, a projected screen will appear which you can see in the following image.

C# WPF Tutorial - Basic Understanding - Visual Studio Project Screen

C# WPF project is divided into two screens, one for the XAML (A Language which generates UI) and the second is dot CS file (CS mean csharp, this file contains C# Code).

In the XAML file, you can write code to generate UI or you can drag and drop components from Toolbox which is shown in the left panel. Each UI component can be manipulated from a C# file, if you want to take some input and then process that to show to the user, you can do that in a C# file.

In the right section, you can see the project structure which is below the solution. There are three important files in the structure.

  1. App.config, which contains configuration data of the project, is sometimes used to declare static information also which is used inside the project. In this file state or project is also declared, like how the project is started.
  2. App.xaml, contains the global UI component templates or definitions which affect the whole UI of the application. You can define global rules for each component here.
  3. MainWindow.xaml, is the main file of the project in which you define UI and logic for your application. Whatever you did in this file, that actually is your software.

Note:
Each xaml file is associative with the cs file, which means App.xaml and MainWindow.xaml also contains the Apps.cs and MainWindow.cs

For more details, you can watch the video.