What is XAML in VB.NET

Here we see what is xaml, attribute, and Implementation of button Click event handler in xaml.
  • 2344

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.


x2.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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.