XML
  Home arrow XML arrow Page 2 - XAML in a Nutshell
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 
VeriSign Whitepapers 
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

XAML in a Nutshell
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2007-03-29

    Table of Contents:
  • XAML in a Nutshell
  • Basic Rules for XAML Elements
  • Elements
  • Control Elements

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    XAML in a Nutshell - Basic Rules for XAML Elements


    (Page 2 of 4 )

    XAML developers need to be aware that in order for application logic developers to access specific XAML elements, the elements must be named using either the Name or ID attribute. Developers will use one of these attributes to reference and manipulate the element directly from code. In Example 3-1, the
    Button ’s Name attribute was declared as MyButton . The same name was then used in both code examples to reference and directly access the object.

    There are three basic rules to follow when declaring XAML elements:

    1. XAML is case-sensitive. Element and attribute names must be properly cased.
    2. All attribute values, regardless of data type, must be enclosed in double quotes.
    3. The resulting XML must be well-formed.

    The basic syntax for declaring XAML elements and attributes is:

      <ElementName AttributeName="Value" AttributeName="Value" ... />

    A simple login user interface, as shown in Figure 3-1, could be described with the code in Example 3-5, which illustrates these basic rules. Note the careful atten tion to case in declaring elements and attributes, the enclosure of all attribute values (regardless of underlying data type) in double quotes, and the fact that all elements are well-formed and closed with an end tag.


    Figure 3-1.  A simple user-login XAML page

    Example 3-5. A simple login user interface

    <StackPanel 
        xmlns=http://schemas.microsoft.com/ winfx/avalon/2005
        HorizontalAlignment="Left"
        Margin="10">
        <Label
           Margin="5 "
           Content="Username" />
        <TextBox
           Margin="5"
           BorderBrush="Blue"
           BorderThickness="1"
           Background="AliceBlue"
           Foreground="Black"
           Width="200"/>
        <Label
           Margin="5"
           Content="Password" />
        <PasswordBox
           Margin="5"
           BorderBrush="Blue"
           BorderThickness="1"
           Background="AliceBlue"
           Foreground="Black"
           Width="200" />
       
    <Button
           Margin="10"
           Background="AliceBlue"
           Foreground="Black"
           Width="100"
           Height="20"
           Content="Submit" />
       
    </StackPanel>

    Formatting is a matter of style and corporate standards. The format for the exam ples in this book was chosen because it is readable and clearly displays the nesting of elements in more complex markup. Elements can be declared all on one line, or attribute declarations can be split across lines; formatting is completely up to you. Because XAML is compiled into BAML before deployment, the amount of space taken up by elements in a XAML file is irrelevant. There are no advantages to using less space by declaring elements on a single line and no disadvantages to the formatting used in this book. The elements will become binary representations before deployment, and the whitespace will have no impact on the footprint of finished applications.

    Clearly, XAML is comprised of elements and their attributes. The rest of this chapter will examine each of these concepts in depth.

    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