Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Dinesh's Blog
Browse by Tags · View All
brh 20
#SILVERLIGHT 19
#DOTNET 18
silverlight 18
#ASP.NET 15
Silverlight 4.0 9
bing 7
bing maps 6
wcf services 5
map 5

Archive · View All
August 2010 10
September 2010 3
July 2010 3
June 2010 3
October 2010 1

SILVERLIGHT Tutorial - What is XAML?

Aug 19 2010 7:07AM by Dinesh Sodani   

In the previous article I attempted to explain What is XAP file in Silverlight. In this article I will try to explain what is XAML and how it is used in Silverlight. Extensible Application Markup Language (XAML, pronounced zammel) is a declarative XML-based language created by Microsoft which is used as a user interface markup language to define UI elements, data binding, event handlers, and other features. XAML files are XML files that generally have the .xaml file name extension.

Silverlight, WPF and XAML

As explained previously XAML is a XML file which defines the UI elements. This XML file can be read by WPF framework or Silver light framework for rendering. Microsoft first developed WPF and they used XAML files to describe the UI elements to the WPF framework. Microsoft then extended WPF and made WPF/E which helped to render the UI in the browser. WPF/E was the code name for Silverlight. Later Microsoft launched Silverlight officially.
So the XAML just defines the XML structure to represent the UI elements. Both the frameworks i.e. WPF and Silverlight then read the UI elements and render the UI elements in the respective platform.

image

The Role of XAML in Silverlight

  1. XAML is the primary format for declaring a Silverlight UI and elements in that UI.
  2. XAML is the format that is used for declaring styles and templates applied to the logical basis of Silverlight controls and UI.
  3. Silverlight XAML defines the visual appearance of a UI, and an associated code-behind file defines the logic. The UI design can be adjusted without necessarily making changes to the logic in code-behind. XAML in this role simplifies the workflow between individuals who might have a primary visual design responsibility and individuals who are responsible for application logic and information design.

The following example shows the contents of a very basic Silverlight XAML file.

<UserControl x:Class="HelloWorld.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  <Grid x:Name="LayoutRoot">
       
  </Grid>
</UserControl>

The XAML Language XAML Namespace

One particular XAML namespace that is declared in nearly every Silverlight XAML file is the XAML namespace for elements that are defined by the XAML language. By convention, the XAML language XAML namespace is mapped to the prefix x:. The default project and file templates for Silverlight projects always define both the default XAML namespace (no prefix, just xmlns=) and the XAML language namespace (to prefix x:) as part of the root element. The x: prefix/XAML language XAML namespace contains several programming constructs that you will use frequently in your Silverlight XAML. The following are the most common x: prefix/XAML namespace constructs:

  1. x:Key: Sets a unique user-defined key for each resource in a ResourceDictionary. The key token string is used as the argument for StaticResource Markup Extension to retrieve any such resource from another XAML usage.
  2. x:Class: Specifies the CLR namespace and class name for the class that provides code-behind for a XAML page, and names the class that is created or joined by a markup compiler in the Silverlight application model. You must have such a class to support code-behind, or to support being initialized as a RootVisual. It is for these reasons that you almost always see x: mapped, even if there are no resources and you never use x:Name.
  3. x:Name: Specifies a run-time object name for the instance that exists in run-time code after an object element defined in XAML is processed. You use x:Name for element-naming scenarios in the occasional cases where the more convenient FrameworkElement.Name property is not supported.

Case Sensitivity in XAML

The XAML language is fundamentally based on the XML language so XAML as a language is case-sensitive. The names of XAML elements and attributes are case-sensitive. The value of an attribute is potentially case-sensitive; this will depend on how the attribute value is handled for particular properties.

XAML File Compiled or Built on runtime

XAML files are usually compiled rather than parsing on runtime. But it also supports parsing during runtime. When we build a XAML based project, you will see it creates g.cs extension in obi\Debug folder. Therefore, for every XAML file you will find a g.cs file.

Silverlight Client Versions and XAML Parsing

In Silverlight 4, Silverlight uses a different XAML parser than was used in Silverlight 3. The XAML parser is a component of the Silverlight core assemblies. This means that if a client is still using Silverlight 3, that client is still using the previous XAML parser. Moreover, if a Silverlight application indicates that is intended to run against Silverlight 3 based on its application manifest information, then the previous XAML parser is used to load the XAML, even if the client is actually the Silverlight 4 run time. This is enabled because both parsers exist in a Silverlight 4 client, which provides backward compatibility for XAML parsing.

Tags: silverlight, brh, #DOTNET, #SILVERLIGHT, #ASP.NET, Silverlight 4.0, XAML, XAML Namespace, Extensible Application Markup Language, XAML Parsing, WPF and XAML, #XAML,


Dinesh Sodani
30 · 6% · 1807
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]