Skip Navigation LinksHome / Tips / View Tip

Tip: How to set a property in XAML?

+ Add to SilverlightShow Favorites
0 comments   /   posted by Denislav Savkov on Sep 05, 2008
(0 votes)
Categories: General

There are four ways to set a property in XAML. Different syntaxes are supported by different properties.

  1. Using the attribute syntax
  2. <elementName PropertyName="Value"/>

    The value of course is from the type of the property.

  3. Using the property syntax
  4. <elementName>
        <elemenName.PropertyName>
            Value
        </elemenName.PropertyName>
    </elementName>

     

  5. Using the content attribute syntax. This is a special syntax that can be used if the ContentProperty attribute of the class is defined. The ContentProperty attribute specifies the property that accepts the content of element. In the following example the name Value becomes value of the PropertyName property of the class.
  6. C#
    [ContentProperty("PropertyName")]
    public class SomeClass
    {
        ...
        public PropertyType PropertyName {get;set;}
        ...
    }
     
    XAML
    <SomeClass>
        Value
    </SomeClass>
  7. Using the implicit collection syntax. If the content of an element is a collection this syntax allows you to omit the declaration of the collection and only declare the elements. The object of the type of the collection is created automatically. Here is an example, the two declaration are equivalent.
  8. XAML

    <elementName>
        <collectionName>
            <elementOfColloectionType/>
            ...
            <elementOfColloectionType/>
        </collectionName>
    </elementName>
    

    XAML

    <elementName>
        <elementOfColloectionType/>
        ...
        <elementOfColloectionType/>
    </elementName>
     

 

That's it

Share


Comments

Comments RSS RSS
No comments

Add Comment

 
 

   
  
  
   
Please add 2 and 5 and type the answer here:

Join the free SilverlightShow webcast 'Running Silverlight Outside the Browser and with Elevated Trust'. Sept 7th, 8 am - 9 am PDT.
In this live session Chris Anderson will cover configuring and debugging OOB mode, toast notifications, elevated trust, direct file access and much more.
Learn more | Register | See more webinars (hide this)