Вы находитесь на странице: 1из 5

[Type text]

APTECH LIMITED
Education Support Services
Academics ACE –Head Office Mumbai
[Type text]
Article Code : ACE/001
Topic : XAML
PURPOSE : To create, define and use User Interface in .net Technologies
SCOPE/OUTCOMES : To understand the use of XAML to develop user interfaces
more easily in .net Framework technologies.

Introduction to XAML
Overview

XAML simplifies creating a UI for the .NET Framework programming model. You can create
visible UI elements in the declarative XAML markup, and then separate the UI definition from
the run-time logic by using code-behind files, joined to the markup through partial class
definitions. The ability to mix code with markup in XAML is important because XML by itself is
declarative, and does not really suggest a model for flow control. An XML based declarative
language is very intuitive for creating interfaces ranging from prototype to production,
especially for people with a background in web design and technologies. Unlike most other
markup languages, XAML directly represents the instantiation of managed objects. This general
design principle enables simplified code and debugging access for objects that are created in
XAML.

XAML files are XML files that generally have the .xaml extension.

XAML is used extensively in .NET Framework 3.0 technologies, particularly Windows


Presentation Foundation, Silverlight, and Windows Workflow Foundation (WF).
[Type text]
APTECH LIMITED
Education Support Services
Academics ACE –Head Office Mumbai
[Type text]
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 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.
[Type text]
APTECH LIMITED
Education Support Services
Academics ACE –Head Office Mumbai
[Type text]
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 given below 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>
[Type text]
APTECH LIMITED
Education Support Services
Academics ACE –Head Office Mumbai
[Type text]
This can be integrated into a web page if WPF is installed using XBAPs (XAML 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 cannot 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>
[Type text]
APTECH LIMITED
Education Support Services
Academics ACE –Head Office Mumbai
[Type text]
The MySilverlight.js file must contain the code that loads the above XAML code (as an XML file)
under the MySilverlight html element.

Advantages of XAML

1. Designing a user interface is easier with XAML.


2. Code for XAML is shorter than code for previous UI designing techniques and you will
see it in action.
3. XAML designed user interfaces are easier to transfer and present in other
environments.
4. Designing a dynamic UI is absolutely easier with XAML.
5. XAML enables a new world for UI designers and lets all designers build user interfaces
without having any knowledge about .NET development.

Вам также может понравиться