(X) Hide this Join our next live webcast on December 15th, 10 am PDT - Building a Silverlight 4 application end-to-end. Presenter: Gill Cleeren
Check the webinar agenda | Register for the webinar
Skip Navigation LinksHome / Articles / View Article

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 3 and 8 and type the answer here: