#78 – Setting the Value of a Content Property By Setting Child Element
September 28, 2010 2 Comments
You can set the value of a property using an XAML attribute. Consider setting the Text property of a TextBox using an attribute:
<TextBox Height="23" Width="120" Text="Eat Muesli!"/>
You can also set the same property value using property element syntax:
<TextBox Height="23" Width="120">
<TextBox.Text>
Eat Muesli!
</TextBox.Text>
</TextBox>
There is an even simpler way to specify the value of the Text property. Because the TextBox class has identified its Text property as a content property, the value of the Text property can be specified directly as the single child of the TextBox XAML element:
<TextBox Height="23" Width="120">
Eat Muesli!
</TextBox>