Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

3. fejezet - XAML (written by Csaba Biró)

3. fejezet - XAML (written by Csaba Biró)

XAML (eXtensible Application Markup Language) is an XML-based declarative markup language, which simplifies the creation of the graphical user interface (GUI) in the .NET model.

The grammatical system of rules of the  declarative language rules is very easy. Its general design principle is that every element of the XAML document – unless it defines an attribute – is a copy of the .NET class.  The implementation of the XAML files can be carried out with interpretation or translation. Here is an example of the interpretation performing.

After starting a simple editor (e.g. Notepad), type the following code:

    <Page xmlns=""


        <TextBlock Text="Hello World!" />


Save it as HelloWorld.xaml, and open this file in a browser (IE, Firefox). We created our first application in XAML language running in XAML browser.

The implementation with another translation is more common. So, if you want to embed codes written in C#  or Visual Basic language, our passcode have to be translated.

Let’s look an example of it, start the Visual Studio. We are going to work in this developing environment further, so the chapter: ’Error: The source of the reference is not found.’ recommend to read.

Now the following steps are performed in the Visual Studio:

  1. File / New Project

III.1. New project

  1. New WPF Application / Name: HelloWorld

III.2. New WPF application

III.3. Visual Studio IDE

  1. Type the following line between Grid controls.

<TextBlock Text="Hello World!" />

Application code is:

<Window x:Class="HelloWorld.MainWindow"



        Title="MainWindow" Height="350" Width="525">


        <TextBlock Text="Hello World!" />



Run the project. In this case we translate the XAML code (in the example) into the resulting executable file as well.

Note that in the first case the root is the Page (for web pages) element, whereas in the second one the Window element. We will make only desktop applications longer, which has Window root element.

The fundamental files of WPF project

Look through the fundamental files of a WPF project with returning to the HelloWorld examples.

III.4. Solution Explorer

In the Solution Explorer (Chapter XVIII.1.1) an App.xaml file can be found with the MainWindow.xaml file has been used above, its content is:

<Application x:Class="HelloWorld.App"








The application resources and startup settings can be defined in the App.xaml file, which begins with the Application root element.

The StartupUri property point to the first visualized window.


We will deal with the management styles and resources more in Chapter XII.