ARTICLE

What is XAML

Posted by Rohatash Kumar Articles | XAML in VB.NET February 18, 2011
Here we see what is xaml, attribute, and Implementation of button Click event handler in xaml.
 
Reader Level:

XAML

XAML is an acronym for extensible Application Markup Language. it is created by Microsoft. XAML is used to create the graphical user interface or UI for a .NET Framework application.

The root element of the XAML must have namespace defined as following:

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation

For example

The below code defines the root

<Window x:Class="WpfApplication54.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

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

    <Grid>       

        <TextBlock>Hello, Rohatash!</TextBlock>

    </Grid>

</Window>

 

Now run it.


x1.gif 

Figure1.gif

 

XAML Properties (attributes)

 

Using the following properties such as name, margin, VerticalAlignment and text property.

 

<Window x:Class="WpfApplication54.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

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

    <Grid>

        <TextBlock Name="textBlock" Margin="5"

                TextAlignment="Center" Text="Hello WPF!" />

    </Grid>

</Window>

 

Now run the application and test it.


x3.gif

Figure2.gif

 

Implementation of button's Click event handler

 

<Window x:Class="WpfApplication56.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

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

    <Button Width="133" Height="24" Name="btnExitApp" Click ="btnExitApp_Clicked">

        Exit Application

    </Button>

    <x:Code>

        private void btnExitApp_Clicked(object sender, RoutedEventArgs e)

    {

    Application.Current.Shutdown();

    }

    </x:Code>

    </Window>

 

Now run it and click on the Button application will shut down.


x3.gif 

Figure3.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor