Introduction to XAML
page 6 of 9
by Keyvan Nayyeri
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 29568/ 478

XAML Attributes

XAML attributes are equivalent to .NET class properties.  You can define attributes inline or explicit.  Explicit definitions help you when your element has several attributes and is getting larger.

Listing 4 shows an inline attribute definition for a Button's Margin attribute and Listing 5 shows an explicit attribute definition for same attribute.

Listing 4

<Button 
  Margin="5">
  Click me!
</Button>

Listing 5

<Button>
  <Button.Margin>5</Button.Margin>
  Click me!
</Button>

Object oriented nature of XAML leads to a behavior that you have seen in HTML before.  Each attribute (which is actually a class property) inherits its parent elements properties or overrides them (if you set that property).

Another key topic in XAML attributes that you should know is Attached Properties.  Some XAML elements get their attributes in other elements and these attributes are named Attached Properties.

For example when you want to use a Grid element (which is very similar to Table in HTML) to lay out your elements, to specify the position of elements in Grid's rows and elements you use Attached Properties.  Each element can get a Grid.Row and Grid.Column which represent the row and column indexes for that element in Grid control.  Listing 6 shows this in action and you can see the output in Figure 2.

Listing 6

<Window x:Class="IntroductionToXAML.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="" Height="94" Width="108"
    >
  <Grid ShowGridLines="True">
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="50" />
      <ColumnDefinition Width="50" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="30" />
      <RowDefinition Height="30" />
    </Grid.RowDefinitions>
 
    <Label Grid.Column="0" Grid.Row="0">0,0</Label>
    <Label Grid.Column="0" Grid.Row="1">0,1</Label>
    <Label Grid.Column="1" Grid.Row="0">1,0</Label>
    <Label Grid.Column="1" Grid.Row="1">1,1</Label>
  </Grid>
</Window>

Figure 2


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 4 and 7 and type the answer here:

User Comments

Title: Good article for biginner   
Name: Bhavesh patel
Date: 4/11/2007 8:47:02 AM
Comment:
Good article for biginner
Title: My point of View Of XAML   
Name: Zaheer Ahmed
Date: 1/20/2007 5:11:49 AM
Comment:
hi i m software engineer and currently i m working on VS.NET 2.0 and i wana switch to 3.0 this article help me to know wht is XAML Thanx
Title: Events in Windows Presentation Foundation   
Name: Keyvan Nayyeri
Date: 12/14/2006 10:22:36 AM
Comment:
Fifth part of these tutorials about Events in Windows Presentation Foundation:
http://aspalliance.com/1088_Events_in_Windows_Presentation_Foundation
Title: Animations in XAML   
Name: Keyvan Nayyeri
Date: 10/25/2006 12:36:09 AM
Comment:
Fourth part of these tutorials about Animations in XAML:
http://aspalliance.com/1050_Animations_in_XAML
Title: Resources in XAML   
Name: Keyvan Nayyeri
Date: 10/12/2006 12:58:37 AM
Comment:
Third part of these tutorials about Resources in XAML:
http://aspalliance.com/1032_Resources_in_XAML
Title: Layout in XAML   
Name: Keyvan Nayyeri
Date: 10/9/2006 2:07:52 PM
Comment:
Second part of these tutorials about Layout in XAML:
http://aspalliance.com/1023_Layout_in_XAML
Title: Thanks   
Name: Keyvan Nayyeri
Date: 10/5/2006 1:54:25 AM
Comment:
Thank you. I think I have many items there ;-)
Title: Added to NetFXGuide.com   
Name: Francesco
Date: 10/5/2006 1:43:36 AM
Comment:
Hi, I just added your intro to the XAML Section of NetFXGuide.com (http://www.netfxguide.com/guide/xaml.aspx).

Best,

Francesco
NetFXGuide.com

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 7/25/2008 3:13:34 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search