#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>
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

3 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?

  2. Pingback: #971 – Items Property is a Content Property | 2,000 Things You Should Know About WPF

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 )

Google+ photo

You are commenting using your Google+ 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

%d bloggers like this: