Feeds

Shine on Silverlight and Windows with XAML

Learn now, pays later

Boost IT visibility and business value

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.

Build a business case: developing custom apps

More from The Register

next story
KDE releases ice-cream coloured Plasma 5 just in time for summer
Melty but refreshing - popular rival to Mint's Cinnamon's still a work in progress
Leaked Windows Phone 8.1 Update specs tease details of Nokia's next mobes
New screen sizes, dual SIMs, voice over LTE, and more
Mozilla keeps its Beard, hopes anti-gay marriage troubles are now over
Plenty on new CEO's todo list – starting with Firefox's slipping grasp
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
Another day, another Firefox: Version 31 is upon us ALREADY
Web devs, Mozilla really wants you to like this one
Secure microkernel that uses maths to be 'bug free' goes open source
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
Cloudy CoreOS Linux distro declares itself production-ready
Lightweight, container-happy Linux gets first Stable release
prev story

Whitepapers

Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Why and how to choose the right cloud vendor
The benefits of cloud-based storage in your processes. Eliminate onsite, disk-based backup and archiving in favor of cloud-based data protection.
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.
Maximize storage efficiency across the enterprise
The HP StoreOnce backup solution offers highly flexible, centrally managed, and highly efficient data protection for any enterprise.