XML
  Home arrow XML arrow Page 3 - Elements and Attributes in XAML
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Elements and Attributes in XAML
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-04-05

    Table of Contents:
  • Elements and Attributes in XAML
  • Document Elements
  • Attributes
  • Assigning XAML Attributes

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Elements and Attributes in XAML - Attributes


    (Page 3 of 4 )

    Attributes are the XML representation of the properties of an element’s corresponding CLR class. The Width attribute of the XAML Button element corresponds directly to the Width property of the System.Windows.Button class. To show the correlation between XAML and CLR classes, Examples 3-7 and 3-8 declare a Button instance and its attributes in both XAML and C#.

    Example 3-7. Button declared in XAML

    <Button
       
    Width="100"
       
    Name="myButton"
       
    Height="20"
       
    Content="This is my button" />

    Example 3-8. Button declared in C#

    Button myButton ;
    myButton.Width=100;
    myButton.Height=20;
    myButton.Content = "This is my button";

    As with the XAML tags for elements, attributes are spelled exactly the same as their corresponding CLR class properties. ( Width = Width , Content = Content ... You get the picture.)

    There are two types of XAML attributes. The first, dependency properties, are public static read-only fields on CLR classes that are derived from DependencyProperty and have declared CLR accessor methods. In other words, the value of dependency properties can be dependent on (hence the name) other variables in CLR classes and, therefore, can only be accessed with a public get or set accessor method to be evaluated properly.

    Dependency properties are like stock certificates. The stock certificate represents a value (money), but the actual amount of money it is worth (its value) is
    deter mined by external calculations and can change at nearly any time. To determine the value of your stock certificate, you must consult the stock exchange and do some multiplication. Dependency properties can also be based on external resources and often rely on calculations to determine their value.

    Dependency property values are determined from a number of different places. The WPF property system searches for the value from the following places in this order:

    1. Storyboards or event triggers that start an animation; property values set by an animation override even local values 
    2. Local value (i.e., <Object Property="value"> )
    3. Property triggers
    4. TemplatedParent ’s template (i.e., that template includes <Setter> )
    5. Style property 
    6. ThemeStyle
    7. Inheritance (from your parent element, not your superclass)
    8. DefaultValue specified when you registered the property (or override metadata)

    These attributes provide support for value expressions, property invalidation, default values, inheritance, data binding, animation, and styling. The property system is complex, so WPF provides simple get and set accessor methods to manipulate these attributes.

    The second type of attribute supported in XAML is the common language runtime property. Common language runtime properties are standard read/write CLR class properties that can be accessed directly and do not require get or set accessor methods, although they generally have them.

    Both dependency properties and common runtime properties are accessed in XAML using the same techniques. The difference between them is important only when you are using more advanced techniques, such as defining styles or triggers that act upon a specific attribute. Some attributes of elements must reference a dependency property, so you need to know which attributes are dependency properties and which are not.

    More XML Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "The Basics of XAML," published by...
     

    Buy this book now. This article is excerpted from chapter 3 of The Basics of XAML, written by Lori A. MacVittie (O'Reilly, 2006; ISBN: 0596526733). Check it out today at your favorite bookstore. Buy this book now.

    XML ARTICLES

    - More on Triggers and Styles and Control Temp...
    - Looking at Triggers with Styles and Control ...
    - A Closer Look at Styles and Control Templates
    - Styles and Control Templates
    - Properties and More in XAML
    - Elements and Attributes in XAML
    - XAML in a Nutshell
    - Importing XML Files into Access 2007
    - Using MSXML3.0 with VB 6.0
    - MSXML, concluded
    - MSXML, continued
    - MSXML Tutorial
    - Generating XML Schema Dynamically Using VB.N...
    - XSL Transformations using ASP.NET
    - Applying XSLT to XML Using ASP.NET





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway