#78 – Setting the Value of a Content Property By Setting Child Element

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>

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

2 Responses to #78 – Setting the Value of a Content Property By Setting Child Element

  1. Gary Lowe says:

    Great concept for your site. I have it saved as a favorite. I am new at this. Question – How do I determine with properties of a specific class is designated as the content property?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 131 other followers