#34 – ContentControl

Content controls are a category of controls that can hold a single nested element, which represents its content.  Since the nested element can be anything, controls that derive from ContentControl can store a variety of different types of content.

Content controls have a Content property, which points to the single element that they contain.  The element is often an UIElement, but can be any .NET object.

Here’s an example, with CheckBox using a DatePicker as its content.

 <CheckBox Height="31" HorizontalAlignment="Center" Name="checkBox1" VerticalAlignment="Center">
     <DatePicker Name="datePicker1"  />
 </CheckBox>

Note that because the Window class is a content control, a Window may have only one child element.

You can effectively include a collection of controls in a content control by including as its content a single container object that in turn contains other elements.  (E.g. A Button could contain a StackPanel, which would then contain other elements).

Advertisements

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

4 Responses to #34 – ContentControl

  1. Pingback: #300 – Button is a ContentControl « 2,000 Things You Should Know About WPF

  2. Pingback: #504 – GroupBox Basics « 2,000 Things You Should Know About WPF

  3. Pingback: #836 – Setting a ContentControl’s Content to a CLR Object | 2,000 Things You Should Know About WPF

  4. Pingback: #883 – ScrollViewer Is a ContentControl | 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: