Recommended

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

Did you notice our new Silverlight-based Showcase section ? Check it out to get a bird's eye view of all showcases featured on SilverlightShow, with a quick thumbnail preview for easier browsing. Want to view the most recent showcases only? Use Group by Month option for a chronological listing.
This is the second redesigned, entirely Silverlight-based section in SilverlightShow, after the new Books section. We look forward to your feedback on both! (hide this)