Blue Theme Orange Theme Green Theme Red Theme
 
Mindcracker MVP Summit 2012
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Discover the top 5 tips for understanding .NET Interop
Search :       Advanced Search »
Home » XAML » XAML - Putting XML to Work

XAML - Putting XML to Work

XML is designed to store data. Microsoft extends the usefulness and power of XML in form of XAML by making it a .NET programming language. Now as a developer, you may find yourself scripting XAML tags to write Windows or Web applications.

Author Rank :
Page Views : 15140
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

XAML becoming a new HOT wave in Microsoft Windows Longhorn programming model. XAML syntactically inherited from XML is a scripting programming language used to write applications that covers both Windows and Web worlds.

Microsoft is well-known and a proven expert in evolving new technologies based on existing technologies by inheriting from the existing technologies, adding new features to them and improvising the existing features. Microsoft .NET Framework and C# language are the best example of it and XAML is no exception.

XML is designed to store data. Microsoft extends the usefulness and power of XML in form of XAML by making it a .NET programming language. Now as a developer, you may find yourself scripting XAML tags to write Windows or Web applications. Besides the easy to use and understand, XAML is flexible enough to provide options to use any .NET programming language as codebehind. Not only you can write the UI definitions, such as size, color, and layout of Windows but you can also write the events and methods in XAML files.

XAML takes advantage of existing XML syntaxes. Almost every .NET developer is familiar with XML. If you are not, you better get started now.

What is XAML?

XAML (Extensible Application Markup Language) is a new scripting language based on XML that allows Longhorn developers to build and managed UI applications via scripting. If you remember Windows Forms model, the settings of a Form and its child controls were used to store in a .cs file with all the attributes of the Form and controls. Now, all these attributes can store in an xaml file and that can run without any additional code. For example, the following code shows how to create a Form with a button saying "Hello, C# Corner".

<?xml version="1.0" standalone="yes"?>
<Window>
    <Button>Hello, C# Corner</Button>
</Window>

To run this code, simply type this code in a text editor, save as xaml extension and double click on it. Of course you have to install Longhorn SDK on your machine if you are not working on Longhorn.

Similar to the above sample code, XAML has tags and attributes for every possible Windows control. You can also embed your code (C# or VB.NET) in an XAML file.

Why XAML? Another Scripting Language?

XML was designed to store data. There is no concept of presentation or events. XAML extends the functionality of XAML by adding user-interfaces and events. Now you can write a fully functional Windows Longhorn application in XAML that will work on both Windows or Web environments. The main purpose of XAML to bring both Windows and Web programming worlds together.

As I said earlier, many of the programmers (Microsoft as well as non-Microsoft) are already familiar with XML and how about a language that looks familiar to these XML developers? Here comes Microsoft with XAML. After the success of C#, one can't doubt the success of XAML.

How does XAML Work?

If you are familiar with Windows Forms, a Form represents a window. A window has properties such as width, height, background color, foreground color and so on. These property values can be set at design-time as well as at run-time. In case of design-time, the values are stored in a file that is associated with a window. When a C# compiler compiles the code, the values of a window properties get stored in the executables.

In case of XAML, a panel represents a window. The values of the panels are stored in the XAML itself in form of XML attributes and elements. When you open an XAML file in browser (Windows Longhorn), the operating system is smart enough to read the XAML tags, elements, and attribute values and creates a window with the given attribute and element values.

All controls or windows in XAML have a predefined tag and each of these tag has properties related to that control or window. For example, the following code for Button tag sets a few properties of Button control:

<Button Width="20" Height="10">OK Button</Button>

XML can have CodeBehind Files

Similar to ASP.NET pages, you can use any .NET programming language to write code for XAML events. For example, you can use C# language to write your code and let XAML provides the layout. An XAML file can embed C# code or it can be stored in a separate codebehind (.cs) file.

XAML replacement of Windows Forms and ASP.NET

True. XAML can be used in place for both Windows Forms and ASP.NET. Now you can write a single application in XAML that would work for both Windows and Web users. There is no need to use two different technologies for two different types of users. Similar to Windows Forms, XAML also support codebehind programming using a new technology called Avalon. Avalon is used to write user-interface applications programmatically.

However, both Windows Forms and ASP.NET will still be used for operating systems that don't support Windows Longhorn applications.

Avalon: Object Model for XAML

Avalon is an object-oriented class library that provides an object model for XAML. All the controls in XAML has a class associated with it in Avalon that can be used to write applications programmatically. See Avalon Section for more details.

Summary

In this article, I discussed the need of XAML and why developers may want to think about moving to XAML. XAML is a technology to write a single application that targets both Windows and Web users without any modifications.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Mahesh Chand
Mahesh is the founder of C# Corner and Mindcracker Network, an author of several .NET programming books and a Microsoft MVP for 6 consecutive years. In his day to day work, Mahesh is a Senior Software Consultant with over 14 years of IT industry experience building systems for Financial and Banking, Engineering & Architectural, Imaging, Construction, Biological & Pharmaceuticals, Healthcare and Education industries. His expertise is Windows Forms, ASP.NET, Silverlight, WPF, WCF, Visual Studio 2010, SQL Server, and Oracle.  If you are looking for a Sharepoint, Windows Forms, ASP.NET, WPF, Silverlight, C#, VB.NET, Oracle, and SQL Server Consultant in Philadelphia area or remote location, drop me a line at MAHESH [AT] C-SHARPCORNER [DOT] COM.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
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.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Comments

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.