Home » Silvelright 3.0

Silverlight 3.0 XAML Demystified – The Basics

12. July 2009 by Joseph Ghassan 52 Comments

XAML represents the UI backbone of Silverlight.. It was firstly introduced in WPF ( Windows Presentation Foundation) as the main tool for windows developers to create rich user interfaces. Seeing that Silverlight was a subset of WPF, it was easy to port this markup language to adopt it also in it.

In this article, you will get a detailed look at XAML by exploring important tags and rules which are important to know to be able to build sophisticated Silverlight user interfaces.

 

xamllogo

 

Quick Facts

  • XAML is pronounced as ‘Zammel’.
  • XAML stands for Extensible Application Markup Language.
  • It is based on the XML format.
  • All XAML elements are case sensitive.
  • Many XAML attributes’ values are case sensitive. For instance, the Name attribute’s values of an element are case sensitive.
  • Every element in a XAML document maps to an instance of a Silverlight class. The name of the element matches the name of the class exactly.
<Grid x:Name="LayoutRoot" Background="White">

</Grid>

internal System.Windows.Controls.Grid LayoutRoot;
 
  • Some elements known as Containers, such as Grid can contain other elements.
<Grid x:Name="LayoutRoot" Background="White">
<Button x:Name="btnDeepInConcept" Content="Get Deeper"></Button>
</Grid>
 
  • If the element does not contain any object ( usually object keyword is reserved for programming languages like C# as for element is for markup languages as XHTML or XML), you can declare the element using a self-contained closing tag.
<Canvas>
<Rectangle />
</Canvas>

 

  • All XAML elements can be declared without assigning a value to the Name property as long as you aren’t going to use it in your code behind. In Windows Forms application, usually this will result in a compilation error.
  • In All XAML documents, there can be only one top-level element. (Single rooted hierarchy). A bar-bones XAML document looks like this : ( A Silverlight ‘page’ is represented by the UserControl class)

 

<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DaisleyHarrison.Silverlight.HtmlTextBlock;
assembly=DaisleyHarrison.Silverlight.HtmlTextBlock"

Width="400" Height="300">
<Grid x:Name="LayoutRoot">

</Grid>
</UserControl>

 

XAML Namespaces

  • XAML Namespaces are represented by xmlns and xmlns:x attributes as shown in the code snippet above.
  • xmlns stands for xml namespace or xaml namespace.
  • The default namespace for Silverlght Client presentation which represents Silverlight 3 classes like the Grid and UserControl is always mapped with xmlns to :
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

  • The default namespace for Silverlight XAML language namespace is always mapped with xmlns:x to :
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

  • These namespaces are required for the XAML parser to be able to read the elements definitions that the XAML markup references.
  • As shown above these namespaces are declared using attributes. You can declare theses namespaces inside any XAML element, but convention dictates to declare them in the root element and all nested elements will use them.
  • You can declare your own namespace in a XAML document to reference a custom control you want to use in your XAML document. You define your custom prefix ctrl the .NET Namespace which your classes are included GVControls and finally your assembly name GvLibrary. In this case, all your classes in GvLibrary.dll can be referenced using the prefix ctrl as shown below :
<UserControl x:Class="SilverlightApplication1.Page"
xmlns:w="clr-namespace:GvControls;assembly=GvLibrary"
...
<ctrl:HotButton Text="Click Me!" Click="DoSomething"></ctrl:HotButton>

 

  • the X:Class Attribute specifies the code behind class for the XAML page. it is derived from the UserControl class.
namespace SilverlightApplication1
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();


}


}
}

  • To manipulate XAML elements programmatically from code behind you assign to an element a unique id using the attribute x:Name.
<Grid x:Name="LayoutRoot">

</Grid>
 
public Page()
{
InitializeComponent();

this.LayoutRoot.Visibility = Visibility.Collapsed;

}



In the next article, we will look at XAML events and properties.
 
Joseph Ghassan

Comments

Balaji
India Balaji said:

xaml books

payday loans
United States payday loans said:

I guess there's always an easier way ...

Internet Marketing
United States Internet Marketing said:

People use search engines to locate what they need on the web. So the importance of search engine optimization (SEO) and search engine marketing (SEM) is obvious to most. And with so much being written on the subjects, we figured the tactic was well understood.

public relations sydney
United States public relations sydney said:

Where this programming finds the application?

Joseph
United States Joseph said:

What do you mean ?

payday loans
United States payday loans said:

Just wanted to say thanks for this.

how can nili lotan dress
United Kingdom how can nili lotan dress said:

Interesting article. You make some good points. Thank you again.

cash loans
United States cash loans said:

Hmmm interesting stuff

cork flooring
United States cork flooring said:

Where this program finds major application?Give further details regarding this topic.

designer jeans
United Kingdom designer jeans said:

Thanks for posting this article. I am definitely tired of struggling to find relevant and intelligent commentary on this subject. Everyone nowadays goes to the very far extremes to either drive home their viewpoint of that everybody else in the globe is wrong. Thanks for your consise and relevant insight.

Price Tags
United States Price Tags said:

I understand now what Silverlight is. Most people who write about it speak like nerds and don't explain it in layman terms so I can understand. You did it the right way.

Speed Dating New York
United States Speed Dating New York said:

The demystification was necessary for me to understand if Silverlight is a technology that I want to use in my applications.

payday loans
United States payday loans said:

Nice resource. rss feed added

fast payday loans
United States fast payday loans said:

I guess there's always an easier way ...

TORRENT SEARCH
United States TORRENT SEARCH said:

Thank you for this article. I really found useful facts about XAML; especially  exploring important tags and rules which are necessary to know to be able to build sophisticated Silverlight user interfaces.
Thanks!

wrap clothing
United Kingdom wrap clothing said:

Interesting information. I will add this blog to my link exchange site.

Joomla Templates Club
United States Joomla Templates Club said:

I find your post so amusing as I can see lots of ways and technique coders do. I will surely keep coming back for more here. Cheers!

seo company
United States seo company said:

  It is good to see you verbalise from the heart and your clarity on this important subject can be easily observed.

Loans in Alabama
United States Loans in Alabama said:

I never saw a pessimistic general win a battle

Life insurance
United States Life insurance said:

Hi,

Interesting read, thanks for helping keep me busy at work ;)

SEO
United States SEO said:

Hi,

Why didn’t I find this post earlier? Keep up the good work!

Apex Professionals
United States Apex Professionals said:

This is a cool screen idea ! It is very interesting indeed.Thank you for your info.i love to read all info.This article gives the light in which we can observe the reality.

Rabeeh Abla
Lebanon Rabeeh Abla said:

Great Article Joseph, love to read more about Silverlight article at your website

CSPSolutions
Lebanon CSPSolutions said:

CSPSolutions services provide optimized solutions, solutions for problems that have complete or partial solution. Our services were created to achieve such goals.

Joseph
Lebanon Joseph said:

Thanks Rabeeh, I heard that you are leaving Globalvis. IT IS ABOUT TIME DUDE !!!!

internet dating
United States internet dating said:

Hi,
   Nice job, it’s a great post. The info is good to know!

Plastic Surgery
United States Plastic Surgery said:

I will keep visiting this blog very often.It is good to see you verbalise from the heart and your clarity on this important subject can be easily observed.

online payday loans
United States online payday loans said:

Let me tell you the secret that has led me to my goal. My strength lies solely in my tenacity.

international moving
United States international moving said:

I would love to read more about this topic.Don’t stop blogging! It’s nice to read a sane commentary for once.Excellent read, I just passed this onto a colleague who was doing a little research on that.

online payday loans
United States online payday loans said:

Thinking will not overcome fear but action will.

playedonline
United States playedonline said:

Very useful informations about these subject. Great info.I like all your post.Interesting article..

Online Sweepstakes
United States Online Sweepstakes said:

Thanks for this very useful info you have provided us. I will bookmark this for future reference and refer it to my friends.

flash development
United Kingdom flash development said:


Thanks for sharing all the above. Your blog is so educationally based that I was just afraid to read it as not to feel unqualified.

link wheel service
United States link wheel service said:

It's very informative posting, actualy i'm new in the domain matter, so this writing help me much increase my knowledge.

casino bonus offers
United States casino bonus offers said:

Really appreciate this post. It’s hard to sort the good from the bad sometimes, but I think you’ve nailed it!

Online SEO services
India Online SEO services said:

Great info.I like all your post.I will keep visiting this blog very often.It is good to see you verbalise from the heart and your clarity on this important subject can be easily observed..We Provide you the best Online SEO Services with high quality.

bookmarkme
United States bookmarkme said:

Wow! i agree! i’ve been searching for so long for a site where i could find everything that i want, and i’ve just found it!! really, i’ve visited your blog, and it’s amazing, i will keep visiting

bookmarking-site
United States bookmarking-site said:

This is a cool screen idea ! It is very interesting indeed.Thank you for your info.i love to read all info.This article gives the light in which we can observe the reality.

psoriasis skin care
psoriasis skin care said:

Great article I will link to it from my psoriasis skin care website.  Thank you.

buy cheap makeup
buy cheap makeup said:

Great article I will link to it from my buy cheap makeup website.  Thank you.

graphic design in melbourne
United States graphic design in melbourne said:

I feel a lot more people need to read this, very good info!

Link wheel service
India Link wheel service said:

It’s nice to read a sane commentary for once.We are offering premium link wheel services with unique content and wheel promotion to social bookmarking sites.We are different from other link wheel service providers..

Whiplash Compensation
United States Whiplash Compensation said:

Thanks for sharing this information. I found it very informative as I have been researching a lot lately on practical matters such as you talk about...and do not forget

Forum posting service
United States Forum posting service said:

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!

Colorado Mortgage
United States Colorado Mortgage said:

Thank you so much for taking my comments on board....I am so glad I bought this app and so looking forward to the future updates

teeth whitening
United States teeth whitening said:

The great accomplishments of man have resulted from the transmission of ideas of enthusiasm.

attract women
United States attract women said:

Hi,
  Sensational info. I look forward to seeing more.

silver baby gifts
United States silver baby gifts said:

This is really quality sharing. Great way of presentation and if you are searching for low rates on gift items then logon to our site since we provide lowest Discount Priced Sterling Silver Baby Cups and Silver Baby Gifts, Baby Comb and Brush sets, Baby Porringers, Baby Rattles, Silver Baby Teething Rings, Discount Silver Picture Frames, Sterling Silver Baby Cups Silver. Discount Prices on all baby cups and baby gifts.

Eli Wilner Master Framer
United States Eli Wilner Master Framer said:

xmal is the bomb i use that in all of my development tools frameworks.  .net is a awesome thing.  you should take this an put it on a picture frame or an antique frame or something.

Debt solutions
United States Debt solutions said:

I will keep visiting this blog very often.MOreover, the Debt solution website is split up it into the different solutions we can offer you professional advice on, so if you know what you are looking for you can go straight there. If you are unclear as to what option could suit you best then take our Debt Solutions Calculator to give you a better understanding of the options.

Sex DVD
United States Sex DVD said:

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!

paper writing service
United States paper writing service said:

Great for all XAML beginners.

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading