Feeds

Shine on Silverlight and Windows with XAML

Learn now, pays later

The Power of One Brief: Top reasons to choose HP BladeSystem

Web bling tone Extensible Application Markup Language, or XAML, lies at the heart of Microsoft's rich-client strategy. The user interface for both Windows Presentation Foundation (WPF) and Silverlight, which is mostly a subset of WPF, is typically defined in XAML.

It is, therefore, something Windows developers will have to get to grips with if they want to stay in tune with Microsoft's latest and - arguably - most ambitious technology roadmap. Even if WPF itself never really takes off, Silverlight is almost certainly going to be big in Microsoft circles.

But what is XAML? It is easy to call it an XML language for defining a graphical user interface (GUI), but that is not quite right. Microsoft calls it "a system for representing structured information," which is about as generic as you can get, and reveals in its document XAML Object Mapping Specification 2006, here, that although XML is "a common format for XAML... any physical representation may be used."

Editing XAML in Visual Studio 2008

Visual Studio 2008 brings IntelliSense to editing XAML

It is also important to distinguish the XAML system from specific XAML vocabularies, such as WPF. Microsoft also uses XAML for Windows Workflow Foundation (WWF), using a different vocabulary that has nothing to do with GUIs. A better stab at defining XAML is to call it a declarative programming language for .NET, or a means of representing a graph of .NET objects.

It turns out that XAML has an uneasy relationship with XML. All the XAML documents you are likely to see are valid XML, but validating them as XAML is not easy. Microsoft explained back in 2006 why it could not develop a satisfactory XML schema for WPF.

The problem is not the core XAML, usually the namespace with an "X" prefix in a XAML document, but the WPF vocabulary, usually the default namespace. Visual Studio 2005 used a huge XamlPresentation2006.xsd that worked mostly but not always. Visual Studio 2008 replaced this with a language service like that used to support IntelliSense for C# and Visual Basic. While this works better, it is unfortunate for anyone wishing to use other XML tools for XAML editing.

XAML has features that simplify the way it maps to the .NET API. Several of these relate to setting property values. Typically XML does this with attributes, but this is awkward when a property is a complex object. XAML supports property elements, which use dot syntax to define objects that are properties of the containing object. Here is an example:

<Rectangle Height="20" Width="50" >
  <Rectangle.Fill>
   <SolidColorBrush Color="Gold" />
  </Rectangle.Fill>
</Rectangle>

It so happens that in this case you can do the same thing with a conventional attribute:

<Rectangle Height="20" Width="50" Fill="Gold" />

How does the XAML parser know that the string "Gold" must be converted to a SolidColorBrush? This is done through a Type Converter, a class that in this example converts a string to a new SolidColorBrush object.

Type Converters extend the number of properties that can be set as attributes, but do not deal with every possibility. In this example, if you wanted to use a different kind of brush, you would have to use the verbose property element syntax, or possibly a Markup Extension.

Securing Web Applications Made Simple and Scalable

More from The Register

next story
Whoah! How many Google Play apps want to read your texts?
Google's app permissions far too lax – security firm survey
Chrome browser has been DRAINING PC batteries for YEARS
Google is only now fixing ancient, energy-sapping bug
Do YOU work at Microsoft? Um. Are you SURE about that?
Nokia and marketing types first to get the bullet, says report
Microsoft takes on Chromebook with low-cost Windows laptops
Redmond's chief salesman: We're taking 'hard' decisions
EU dons gloves, pokes Google's deals with Android mobe makers
El Reg cops a squint at investigatory letters
Big Blue Apple: IBM to sell iPads, iPhones to enterprises
iOS/2 gear loaded with apps for big biz ... uh oh BlackBerry
OpenWRT gets native IPv6 slurping in major refresh
Also faster init and a new packages system
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
prev story

Whitepapers

Top three mobile application threats
Prevent sensitive data leakage over insecure channels or stolen mobile devices.
The Essential Guide to IT Transformation
ServiceNow discusses three IT transformations that can help CIO's automate IT services to transform IT and the enterprise.
Mobile application security vulnerability report
The alarming realities regarding the sheer number of applications vulnerable to attack, and the most common and easily addressable vulnerability errors.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
Consolidation: the foundation for IT and business transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.