Monday, November 23, 2009  
Google
Web pcquest.com

CIOL Network sites

Search by Issue | Sitemap | Advanced Search

• For most updated version of DQ TOP 20 issue, visit dqindia.com • Ad : Play and Plug ERP by IBM

Home > Developers Lab > What is XAML Programming?

    Enterprise Solutions
    Hands On
    ITstrategy

    Developer

    Tech Forum

    SMB Forum

    Trends

    Shootout

    Reviews
    Editorials
    Linux and Open Source
    Technology
    Extraedge

    IT Careers

    Vertical Focus

Subscribe to Print magazine.


now!


Newsletter


What is XAML Programming?

A new markup language in the forthcoming Windows Longhorn that integrates Windows and Web programming
Vinod Unny

Monday, January 05, 2004

Windows application programming has always differed from applications that were run from the Web. That is, not only the languages, but even the programming model were completely different. 

There were previous attempts to bridge this gap. For instance, HTAs (HTML Applications) let you create HTML + Script based files that can be run directly on the user’s machine as a standalone application. Also using Visual Studio.NET, you could program for the Web as easily as you could for the desktop—by simply writing event handlers for buttons and other controls using the same language as you would for the desktop application (VB.NET or C#).

However, internally both were quite different in the way the code was written and structured. For instance, take a look at the first code block below which is for a simple Windows application that writes “Hello, World” when you click a button on the window.

Public Class Form1
Inherits System.Windows.Forms.Form
#Region “ Windows Form Designer generated code “
...
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
...
Me.Label1.Location = New System.Drawing.Point(8, 16)
Me.Label1.Name = “Label1”
Me.Label1.TabIndex = 0
...
Me.Button1.Location = New System.Drawing.Point(8, 48)
Me.Button1.Name = “Button1”
Me.Button1.TabIndex = 1
Me.Button1.Text = “Click Me!”
...
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label1)
Me.Name = “Form1”
Me.Text = “Form1”
Me.ResumeLayout(False)
End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = “Hello, World!”
End Sub
End Class

The code above declares two controls (a label and a button), sets some properties and places them on the form. The button also has an event handler for the Click event which changes the Text property of the label to “Hello, World”. The same stuff in ASP.NET looks like the following.

<%@ Page Language=”vb” AutoEventWireup=”false” Codebehind=”PCQTest.Aspx.vb” Inherits=”indevNET.PCQTest”%>
<HTML> <HEAD> <title>PCQTest</title> </HEAD>
<body MS_POSITIONING=”GridLayout”>
<form id=”Form1” method=”post” runat=”server”>
<asp:Label id=”Label1” style=”Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px” runat=”server”></asp:Label>
<asp:Button id=”Button1” style=”Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 32px” runat=”server” Text=”Click Me”></asp:Button>
</form>
</body>
</HTML>

And the code-behind has:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = “Hello, World”
End Sub

As you can see, the same functionality is given by two completely different programming layouts. Windows programming has all the properties and code in a single place with explicit coding. Whereas the Web application is declarative using markup and with a code behind that lets you code in a different place.

XAML (pronounced ZAMEL) comes in at this point to solve this conundrum and give a unified programming model for both Web and Windows. Although XAML will be available from Microsoft only in the next version of Windows, codenamed Longhorn, there are ways you can do XAML programming right now itself. For instance, Xamalon lets you create XAML applications for WinXP right now.

XAML, which stands for eXtensible Application Markup Language, uses an XML-derived syntax to build applications using declarative statements. Take a look at the XAML code below for an example.

<Button Width=”100px”> OK
<Button.Background>Blue</Button.Background>
</Button>

This simply creates an application with a single OK button with a blue background. Similarly, you can easily set more properties, either inline in the main tag (just like in HTML) or explicitly as shown above.

How does XAML work? To put it simplistically, each control in the .NET framework for Longhorn is ‘mapped’ to a XAML tag. Each property is also mapped as the tag’s attribute. So you can declare the entire UI for the Windows application in the declarative statements. You can even do more advanced things by setting some controls to react or manipulate other controls for changing orientation, creating animation effects and more without writing any kind of ‘normal’ code! Executing a XAML file converts the tags to C# classes in the background and then run within the .NET framework context. 

Of course, when you do need to add more functionality to the application, you can have inline C#/VB.NET code or as in ASP.NET, create the code in a ‘code-behind’ file and work on that instead. This means that a UI designer can work on the Windows application UI using the XAML file, and the developer can work with the backend code just like what one does with large Web based projects now! 

This is the point at which we see the integration of Windows and Web-based applications. Already Longhorn has many new integration features, that let you forget about which technology you are using, and instead just get the best out of all of them. However, since Longhorn is still in very early stages, it would be interesting to keep an eye on all the new things happening there.

Vinod Unny, Enterprise InfoTech



Page(s)   1   

End of the article

PC Problems? Get a solution in 24 hours. Ask Tech Expert




Untitled Document



ZTE:Leading CDMA Technology


Extraordinary Networks:Freedom of Choice


Message boards

Discuss this and many other IT topics at the
CIOL message board

Previous Stories

ASP .NET like Validations with Java

.NET’s Upcoming Version

Remote Scripting with PHP

   
 

 
 

Magazine Subscription | RQS | Contact Us | Team PCQuest | Advertising - Print | jobs@cybermedia