There are four ways to set a property in XAML. Different syntaxes are supported by different properties.
- Using the attribute syntax
<elementName PropertyName="Value"/>
The value of course is from the type of the property.
- Using the property syntax
<elementName>
<elemenName.PropertyName>
Value
</elemenName.PropertyName>
</elementName>
- 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.
C#
[ContentProperty("PropertyName")]
public class SomeClass
{
...
public PropertyType PropertyName {get;set;}
...
}
XAML
<SomeClass>
Value
</SomeClass>
- 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.
XAML
<elementName>
<collectionName>
<elementOfColloectionType/>
...
<elementOfColloectionType/>
</collectionName>
</elementName>
XAML
<elementName>
<elementOfColloectionType/>
...
<elementOfColloectionType/>
</elementName>
That's it