Senin, 05 Agustus 2013

Basics about XAML in context of WPF Application

XAML, stands for eXtensible Application Markup Language, is a declarative XML based language used for initializing structured values and objects. In the context of WPF, XAML is used to describe visual user interface. The GUI created in XAML can be expressed using any .NET language like C# or VB.

As this is simply based on XML, programmers are able to share and edit content amongst themselves without compilation. Whenever you will create a page or a window in WPF, it will create a XAML document and a code behind file, which together creates the page or window.

Here is the basic XAML code for creating a textblock in Grid element.
<Grid>
        <TextBlock Text="My First WPF Application" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
</Grid>
In the above code use <TextBlock> element to identify the TextBlock control. The FontSize property is used to get or set the font size of the content of the element. Here font size of the text block is 30 pixels.

Horizontal alignment property is used to get or set the horizontal alignment of this element when it is within a parent element like a panel etc. The horizontal alignment may be center, left, right and stretch according to programmer’s requirement. The default value is Stretch.

Vertical alignment property is same as horizontal property. It is also may have four values i.e. center, left, right and stretch programmer’s requirement. The default value is Stretch.

We can also use the above properties like the following code:
<TextBlock Text="My First WPF Application">
<TextBlock.FontSize>30</TextBlock.FontSize>
<TextBlock.HorizontalAlignment>Center</TextBlock.HorizontalAlignment>
<TextBlock.VerticalAlignment>Center</TextBlock.VerticalAlignment>
</TextBlock>
The window will be look like the following screenshot:

Basic about XAML in WPF application

Both type of syntaxes are same. There are many more properties for each elements which will use as per the requirements.

Tidak ada komentar:

Posting Komentar