Wednesday, August 20, 2008

Extensible Application Markup Languag (XAML)

Extensible Application Markup Language


Extensible Application Markup Language (XAML, pronounced zammel () is a declarative
XML-based language created by Microsoft which is used to initialize structured
values and objects. It is available under Microsoft's Open Specification Promise.
The acronym originally stood for Extensible Avalon Markup Language - Avalon
being the code-name for Windows Presentation Foundation (WPF).


Overview


XAML is used extensively in .NET Framework 3.0 technologies, particularly Windows
Presentation Foundation (WPF) and Windows Workflow Foundation (WF). In WPF,
XAML is used as a user interface markup language to define UI elements, data
binding, eventing, and other features. In WF, workflows can be defined using
XAML.


XAML elements map directly to Common Language Runtime object instances, while
XAML attributes map to Common Language Runtime properties and events on those
objects. XAML files can be created and edited with visual design tools such
as Microsoft Expression Blend, Microsoft Visual Studio, and the hostable Windows
Workflow Foundation visual designer. They can also be created and edited with
a standard text editor, a code editor such as XAMLPad, or a graphical editor
such as Vectropy.


Anything that is created or implemented in XAML can be expressed using a more
traditional .NET language, such as C# or Visual Basic.NET. However, a key aspect
of the technology is the reduced complexity needed for tools to process XAML,
because it is based on XML. As a result, a variety of products are emerging,
particularly in the WPF space, which create XAML-based applications. As XAML
is simply based on XML, developers and designers are able to share and edit
content freely amongst themselves without requiring compilation. As it is strongly
linked to the .NET Framework 3.0 technologies, the only fully compliant implementation
as of today is Microsoft's[citation needed].


Technology


A XAML file can be compiled into a .baml (Binary XAML) file, which may be inserted
as a resource into a .NET Framework assembly. At run-time, the framework engine
extracts the .baml file from assembly resources, parses it, and creates a corresponding
WPF visual tree or workflow.


When used in Windows Presentation Foundation, XAML is used to describe visual
user interfaces. WPF allows for the definition of both 2D and 3D objects, rotations,
animations, and a variety of other effects and features.


When used in Windows Workflow Foundation contexts, XAML is used to describe
potentially long-running declarative logic, such as those created by process
modeling tools and rules systems. The serialization format for workflows was
previously called XOML, to differentiate it from UI markup use of XAML, but
now they are no longer distinguished. However, the file extension for files
containing the workflow markup is still "XOML".


Templates


XAML uses a specific way to define Look and feel called Templates, different
from the Cascading Style Sheets syntax, but closer to XBL.


Example


This Windows Presentation Foundation example shows the text "Hello World!"
in the top-level XAML container called Canvas.


<Canvas xmlns="http://schemas.microsoft.com/client/2007"


xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<TextBlock>Hello World!</TextBlock>

</Canvas>


The schema (the xmlns="http://schemas.microsoft.com..."
part) may have to be changed to work on your computer. Using a schema that Microsoft
recommends, the example can also be


<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">

<TextBlock>Hello World!</TextBlock>

</Canvas>


This can be integrated into a web page if WPF is installed using XBAPs (XML
Browser Applications) which are compiled applications running in a sandboxed
environment hosted within the browser. Another way is to use the Silverlight
plugin. The code can not be included directly in an html page; rather it must
be loaded into the page via JavaScript. If .NET 3.0 or later is installed, loose
XAML files can also be viewed on their own in a compatible web browser (including
Internet Explorer and FireFox) in conjunction with the .NET Framework 3.0, without
the need for the Silverlight plugin. Loose XAML files are markup-only files
limited to defining the visual content to be rendered. They are not compiled
with an application.


<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>XAML Example </title>

<script type="text/javascript" src="MySilverlight.js"
/>

<script type="text/javascript" src="Silver.js" />

</head>

<body>

<div id="MySilverlight" >

</div>

<script type="text/javascript">

createMySilverlight();

</script>

</body>

</html>


The MySilverlight.js file must contain the code that loads the above XAML code
(as an XML file) under the MySilverlight html element.

Read More >>

Windows Presentation Foundation

The Windows Presentation Foundation (or WPF), formerly code-named
Avalon, is a graphical subsystem in .NET Framework 3.0 (formerly called
WinFX) and is directly related to XAML.
Version 3.0 of WPF is included with Windows Vista and Windows Server 2008, and
is also available for Windows XP Service Pack 2 or later, and Windows Server
2003. It provides a consistent programming model for building applications and
provides a clear separation between the user interface and the business logic.
A WPF application can be deployed on the desktop or hosted in a web browser.
It also enables rich control, design, and development of the visual aspects
of Windows programs. It aims to unify a host of application services: user interface,
2D and 3D drawing, fixed and adaptive documents, advanced typography, vector
graphics, raster graphics, animation, data binding, audio and video. Although
WinForms will continue to be widely used, and Microsoft has created only a few
WPF applications, the company promotes WPF for line-of-business applications.


Microsoft Silverlight is a web-based subset of WPF that enables Flash-like
web and mobile applications with the same programming model as .NET applications.
3D features are not supported, but XPS and vector-based drawing are included.



Architecture

The WPF architecture. Blue elements are Windows components; brown ones are WPF components.
The WPF architecture. Blue elements are Windows components; brown ones are WPF components.


The architecture of Windows Presentation Foundation spans across both managed
code and native code components; however, the public API exposed is only available
via managed code. While the majority of WPF is in managed code, the composition
engine which renders the WPF applications is a native component. It is named
Media Integration Layer (MIL) and resides in milcore.dll.
It interfaces directly with DirectX and provides basic support for 2D and 3D
surfaces, timer-controlled manipulation of contents of a surface with a view
to exposing animation constructs at a higher level, and compositing the individual
elements of a WPF application into a final 3D "scene" that represents the UI
of the application and renders it to the screen. The media codecs are also implemented
in unmanaged code, and are shipped as windowscodecs.dll.In
the managed world, PresentationCore (presentationcore.dll) provides
a managed wrapper for MIL and implements the core services for WPF,
including a property system that is aware of the dependencies between the setters
and consumers of the property, a message dispatching system by means of a Dispatcher
object to implement a specialized event system and services which can implement
a layout system such as measurement for UI elements.
PresentationFramework (presentationframework.dll) implements the
end-user presentational features, including layouts, time-dependent, story-board
based animations, and data binding.


WPF exposes a property system for objects which inherit from DependencyObject,
that is aware of the dependencies between the consumers of the property, and
can trigger actions based on changes in properties. Properties can be either
hard coded values or expressions, which are specific expressions that evaluate
to a result. In the initial release, however, the set of expressions supported
is closed.The value of the
properties can be inherited from parent objects as well. WPF properties support
change notifications, which invoke bound behaviors whenever some property
of some element is changed. Custom behaviors can be used to propagate a property
change notification across a set of WPF objects. This is used by the layout
system to trigger a recalculation of the layout on property-changes, thus exposing
a declarative programming style for WPF, whereby almost everything, from setting
colors and positions to animating elements can be achieved by setting properties.
This allows WPF applications to be written in XAML, which is a declarative mark-up
language, by binding the keywords and attributes directly to WPF classes and
properties.


The UI elements of an WPF application is maintained as a class of Visual
objects. Visual objects provide a managed interface to a composition tree
which is maintained by Media Integration Layer (MIL). Each element of WPF creates
and adds one or more composition nodes to the tree. The composition nodes
contain rendering instructions, such as clipping and transformation instructions,
along with other visual attributes. Thus the entire application is represented
as a collection of composition nodes, which are stored in a buffer in the system
memory. Periodically, MIL walks the tree and executes the rendering instructions
in each node, thus compositing each element on to a DirectX surface, which is
then rendered on screen. MIL uses the painter's algorithm, where all the components
are rendered from back of the screen to the front, which allows complex effects
like transparencies to be easily achieved. This rendering process is hardware
accelerated using the GPU. The
composition tree is cached by MIL, creating a retained mode graphics, so that
any changes to the composition tree needs only to be incrementally communicated
to MIL. This also frees the applications of managing repainting the screen,
MIL can do that itself as it has all the information necessary. Animations can
be implemented as time-triggered changes to the composition tree. On the user
visible side, animations are specified declaratively, by setting some animation
effect to some element via a property and specifying the duration. The code-behind
updates the specific nodes of the tree, via Visual objects, to
represent both the intermediate states at specified time intervals as well as
the final state of the element. MIL will render the changes to the element automatically.


All WPF applications start with two threads: one for managing the UI and another
background thread for handling rendering and repainting.
Rendering and repainting is managed by WPF itself, without any developer intervention.
The UI thread houses the Dispatcher (via an instance of DispatcherObject),
which maintains a queue of UI operations that need to be performed (as a tree
of Visual objects), sorted by priority. UI events, including changing
a property that affects the layout, and user interaction events raised are queued
up in the dispatcher, which invokes the handlers for the events. Microsoft recommends
that the event handlers only update the properties to reflect new content for
application responsiveness; the new content be generated or retrieved in a background
thread. The render
thread picks up a copy of the visual tree and walks the tree calculating which
components will be visible and renders them to Direct3D surfaces. The render
thread also caches the visual tree, so only changes to the tree need to be communicated,
which will result in updating only the changed pixels. WPF supports an extensible
layout model. Layout is divided into two phases: Measure and Arrange.
The Measure phase recursively calls all elements and determine the size they
will take. In the Arrange phase, the child elements are recursively arranged
by their parents, invoking the layout algorithm of the layout module in use.





Features

The following is a partial list of WPF features.

Graphical Services


  • All graphics (including desktop items like windows) are Direct3D applications.
    • This aims to provide a unified avenue for displaying graphics, as well as more advanced graphical features.

    • Routing the graphics through Direct3D allows Windows to offload some
      graphics tasks to the Graphics Processing Unit found on the computer's
      graphics card. This can reduce the workload on the computer's Central
      processing unit.

    • Supports vector-based graphics, which allow lossless scaling.
    • Supports 3D model rendering and interaction in 2D applications.

    • Interactive 2D content can be overlaid on 3D surfaces, natively.

Interoperability


  • WPF provides interoperability with Win32: Via hosting, one can use Windows
    Presentation Foundation inside existing Win32 code, or one can use existing
    Win32 code inside Windows Presentation Foundation.

  • Interoperability with Windows Forms is also possible through the use of
    the ElementHost and WindowsFormsHost classes.

Media Services

  • WPF provides shape primitives for 2D graphics along with a built-in set of brushes, pens, geometries, and transforms.
  • The 3D capabilities in WPF are a subset of the full feature set provided by Direct3D. However, WPF provides tighter integration with other features like user interface (UI), documents, and media. This makes it possible to have 3D UI, 3D documents, and 3D media.
  • There is support for most common image formats.

  • WPF supports the video formats WMV, MPEG and some AVI files.

  • WPF supports time-based animations, in contrast to the frame-based approach. This decouples the speed of the animation from how the system is performing. -

Animations


  • Time-based animation. Scene redraws are time triggered.

  • Presentation timers are initialized and managed by WPF.

  • Scene changes co-ordinated by using a storyboard.

  • Animations can be triggered by other external events, including user action.

  • Animation effects can be defined on a per-object basis, which can be accessed
    directly from XAML markup.

  • Ships with a set of predefined effects, such as fade out for all
    controls.

Data binding

  • WPF has a built-in set of data services to enable application developers to bind and manipulate data within applications. There exists support for three types of data binding:
    • one time: where the client ignores updates on the server.
    • one way: where the client has read-only access to data.
    • two way: where client can read from and write data to the server.

  • LINQ queries, specifically LINQ to XML, can also act as data sources
    for data binding.

  • Binding of data has no bearing on its presentation. WPF provides data templates to control presentation of data.

User interface


  • A set of built-in controls is provided as part of WPF, containing items
    such as button, menu, and list box. WPF lacks an official DataGrid control
    but 3rd-party vendors are already offering some.

  • A powerful concept in the WPF is the logical separation of a control from its appearance.
    • A control's template can be overridden to completely change its visual appearance.
    • A control can contain any other control or layout, allowing for unprecedented control over composition.
  • Features retained mode graphics, so that applications do not have to be bothered with repainting the display.

Annotations

  • Annotations can be applied on a per-object basis, for objects in a Document or FlowDocument.
  • WPF only provides the capability for creating, storing and managing annotations; each application must expose the UI on their own.

Imaging


  • WPF can natively access Windows Imaging Component (WIC) codecs and APIs
    allowing developers to write image codecs for their specific image file formats.

Effects


  • WPF provides for bitmap effects, however, they are rendered in hardware
    only in .NET Framework 3.5 SP1 or newer. GPU features like pixel shaders are
    not used for bitmap effects.

  • Special effects such as dropshadows and blurring are built in.

Documents

  • WPF natively supports paginated documents. It provides the DocumentReader class, which is for reading fixed layout documents. The FlowDocumentReader class offers different view modes such as per-page or scrollable and also reflows text if the viewing area is resized.

  • Natively supports XML Paper Specification documents.

  • Supports reading and writing paginated documents using Open Packaging Convention.

Text


WPF includes a number of typographic and text rendering features that were
not available in GDI. This is the first Windows programming interface to expose
OpenType features to software developers, supporting both OpenType, TrueType,
and OpenType CFF (Compact Font Format) fonts.


Support for OpenType typographic features includes:


  • Ligatures

  • Old-style numerals (for example, parts of the glyph hang below the text
    baseline)

  • Swash variants

  • Fractions

  • Superscript and Subscript

  • Small caps

  • Line-level justification

  • Ruby characters.

  • Glyph substitution

  • Multiple baselines

  • Contextual and Stylistic Alternates

  • Kerning


WPF handles texts in Unicode, and handles texts independent of global settings,
such as system locale. In addition, fallback mechanisms are provided to allow
writing direction (horizontal versus vertical) handled independent of font name;
building international fonts from composite fonts, using a group of single-language
fonts; composite fonts embedding. Font linking and font fallback information
is stored in a portable XML file, using composite font technology.
The XML file has extension .CompositeFont.


The WPF text engine also supports built-in spell checking. It also supports
such features as automatic line spacing, enhanced international text, language-guided
line breaking, hyphenation, and justification, bitmap effects, transforms, and
text effects such as shadows, blur, glow, rotation etc. Animated text is also
supported; this refers to animated glyphs, as well as real-time changes in position,
size, color, and opacity of the text.


WPF text rendering takes advantage of advances in ClearType technology, such
as sub-pixel positioning, natural advance widths, Y-direction anti-aliasing,
hardware-accelerated text rendering, as well as aggressive caching of pre-rendered
text in video memory. ClearType
cannot be turned off in WPF applications. Unlike the ClearType in GDI or GDI+,
WPF ClearType does not snap glyphs to pixels horizontally, leading to a loss
of contrast disliked by some users.


The extent to which glyphs are cached is dependent on the video card. DirectX
10 cards are able to cache the font glyphs in video memory, then perform the
composition (assembling of character glyphs in the correct order, with the correct
spacing), alpha-blending (application of anti-aliasing), and RGB blending (ClearType's
sub-pixel color calculations), entirely in hardware. This means that only the
original glyphs need to be stored in video memory once per font (Microsoft estimates
that this would require 2 MB of video memory per font), and other operations
such as the display of anti-aliased text on top of other graphics—including
video—can also be done with no computation effort on the part of the CPU. DirectX
9 cards are only able to cache the alpha-blended glyphs in memory, thus requiring
the CPU to handle glyph composition and alpha-blending before passing this to
the video card. Caching these partially-rendered glyphs requires significantly
more memory (Microsoft estimates 5 MB per process). Cards that don't support
DirectX 9 have no hardware-accelerated text rendering capabilities.


Alternative input


WPF supports digital ink-related functionality.


Accessibility


WPF supports Microsoft UI Automation to allow developers to create accessible
interfaces.


XAML


Main article: Extensible Application
Markup Language


Following the success of markup languages for web development, WPF introduces
a new language known as eXtensible Application Markup Language (XAML) (pronounced
"Zammel"), which is based on XML. XAML is designed as a more efficient method
of developing application user interfaces.


The specific advantage that XAML brings to WPF is that XAML is a completely
declarative language. In a declarative programming language, the developer (or
designer) describes the behavior and integration of components without the use
of procedural programming. This allows someone with little or no traditional
programming experience to create an entire working application with no programming.
Although it is rare that an entire application will be built completely in XAML,
the introduction of XAML allows application designers to more effectively contribute
to the application development cycle. Using XAML to develop user interfaces
also allows for separation of model and view; which is considered a good architectural
principle. In XAML, elements and attributes map to classes and properties in
the underlying APIs.


As in web development, both layouts and specific themes are well suited to
markup, but XAML is not required for either. Indeed, all elements of WPF may
be coded in a .NET language (C#, VB.net). The XAML code can ultimately be compiled
into a managed assembly in the same way all .NET languages are, which means
that the use of XAML for development does not incur a performance cost. XAML
can also be compiled and run "on demand" similar to an HTML web-page.


Although XAML has been introduced as an integral part of WPF, the XAML standard itself is not specific to WPF (or even .NET). XAML can also be used to develop applications using any programming API and is in itself language independent. Nevertheless, special care has been taken in developing the WPF APIs to maximize interoperability with the declarative model that XAML introduces.


It is likely that many applications, such as Microsoft PowerPoint and Word,
will support exporting their content to XAML.


There are several subsets (or profiles) of XAML, such as:


  • XAML Presentation (XAML-P) - incorporates all items encompassing WPF v1.0

  • XML Paper Specification (XPS) - a subset of XAML-P for representing fixed
    format documents and used as the spool format for the printing subsystem in
    Windows Vista

There are also profiles specific to Workflow Foundation, and other domain specific subsets will likely emerge in the future.

Tools

There are a number of development tools available for developing Windows Presentation Foundation applications, most currently of beta quality, some commercially released.


  • Microsoft Cider is the XAML designer in the form of an add-in for the Visual
    Studio 2005 IDE for building Windows Presentation Foundation applications.
    It is available in CTP form for Visual Studio 2005, there are no plans for
    an RTM version for Visual Studio 2005. Cider is integrated into Visual Studio
    2008.

  • Microsoft Expression Blend is a designer-oriented tool that provides a canvas
    for the creation of WPF applications with 2D and 3D graphics, text and forms
    content. It generates XAML that may be exported into other tools.

  • Microsoft Expression Design is a bitmap and 2D-vector graphics tool that
    allows export to XAML.

  • XAMLPad is a is a lightweight tool included in the .NET Framework SDK. It
    can create and render XAML files using a split screen UI layout. It also provides
    a tree view of the markup in a panel. An improved version, called XamlPadX
    v3, can be downloaded from the author's blog.

Deployment

  • WPF isn't just for building traditional standalone applications. Its deployment model offers both standalone and XAML Browser Applications (XBAP) flavors. The programming model for building either flavor of application is similar.

    • Standalone applications are those that have been locally installed on
      the computer using software such as ClickOnce or Windows Installer (MSI)
      and which run on the desktop. Standalone applications are considered full
      trust
      and have full access to a computer's resources.

    • XAML Browser Applications (XBAPs) are programs that are hosted inside
      a web browser such as Firefox or Internet Explorer. Hosted applications
      run in a partial trust sandbox environment, and are not given full
      access to the computer's resources and not all WPF functionality is available.
      The hosted environment is intended to protect the computer from malicious
      applications. Starting an XBAP (pronounced "ex-bap") from an HTML page
      or vice versa is seamless (there is no security or installation prompt).
      Although one gets the perception of the application running in the browser,
      it actually runs in an out-of-process executable different from the browser.
      As of the release of.NET Framework 3.0, XBAPs only run in Internet Explorer.
      With the release of .NET Framework 3.5, they also run in Mozilla Firefox
      after installing an XBAP extension.


Microsoft Silverlight


Silverlight (codenamed WPF/E) is a cross-platform, cross-browser, browser plugin
which contains WPF-based technology (including XAML)
that provides features such as video, vector graphics, and animations to multiple
operating systems including Windows Vista, Windows XP, and Mac OS X, with Microsoft
sanctioned 3rd party developers working ports for Linux distributions.
Specifically, it is currently provided as an add-on for Mozilla Firefox, Internet
Explorer 6 and above, and Apple Safari. Silverlight and WPF only share the XAML
presentation layer.


WPF Applications

WPF is intended to be the next-generation graphics API for Windows applications on the desktop. The following are some of Microsoft's own products or other third-party mainstream applications written in WPF:


  • Microsoft Expression Design

  • Microsoft Expression Blend

  • Yahoo! Messenger

  • Nokia Music PC Beta

  • Clear Office Spreadsheet

  • MuvUnder Cover: The Album Art Sleuth

.NET Micro Framework


The .NET Micro Framework includes a GUI object model loosely based on WPF,
although without support for XAML.


References

Read More >>

Popular Posts