Feeds

Shine on Silverlight and Windows with XAML

Learn now, pays later

Providing a secure and efficient Helpdesk

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.

Choosing a cloud hosting partner with confidence

More from The Register

next story
Microsoft on the Threshold of a new name for Windows next week
Rebranded OS reportedly set to be flung open by Redmond
Business is back, baby! Hasta la VISTA, Win 8... Oh, yeah, Windows 9
Forget touchscreen millennials, Microsoft goes for mouse crowd
SMASH the Bash bug! Apple and Red Hat scramble for patch batches
'Applying multiple security updates is extremely difficult'
Apple: SO sorry for the iOS 8.0.1 UPDATE BUNGLE HORROR
Apple kills 'upgrade'. Hey, Microsoft. You sure you want to be like these guys?
ARM gives Internet of Things a piece of its mind – the Cortex-M7
32-bit core packs some DSP for VIP IoT CPU LOL
Lotus Notes inventor Ozzie invents app to talk to people on your phone
Imagine that. Startup floats with voice collab app for Win iPhone
prev story

Whitepapers

A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Beginner's guide to SSL certificates
De-mystify the technology involved and give you the information you need to make the best decision when considering your online security options.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.