Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
1 out of 2 rated this helpful - Rate this topic

ContentControl Class

Represents a control with a single piece of content.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)] 
[ContentPropertyAttribute("Content")] 
public class ContentControl : Control, IAddChild
/** @attribute LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable) */ 
/** @attribute ContentPropertyAttribute("Content") */ 
public class ContentControl extends Control implements IAddChild
LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable) 
ContentPropertyAttribute("Content") 
public class ContentControl extends Control implements IAddChild
<ContentControl>
  Content
</ContentControl>

A ContentControl has a limited default style. If you want to enhance the appearance of the control, you can create a new control template. For more information, see Data Templating Overview. Another typical scenario is to use the ContentControl to show more information about an item selected in an ItemsControl control. For more information, see How to: Bind to a Collection and Display Information Based on Selection.

Content Model: ContentControl is the class from which other content controls inherit. For more information on the content model for ContentControl, see ContentControl Content Model.

The following example shows how to make a style for a ContentControl so that the control has an enhanced visual appearance.

<Style x:Key="ContentCtrl" TargetType="{x:Type ContentControl}">
  <Setter Property="Background" Value="Red"/>
  <Setter Property="Foreground" Value="Green"/>
  <Setter Property="FontSize" Value="20"/>
  <Setter Property="FontWeight" Value="Bold"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type ContentControl}">
        <Grid>
          <!--Keep the Ellipse a circle when ContentControl.Width
              is set.-->
          <Ellipse Width="{TemplateBinding Width}"
                   Height="{TemplateBinding Width}"
                   Fill="{TemplateBinding Background}"/>
            <ContentPresenter VerticalAlignment="Center"
                              HorizontalAlignment="Center"/>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Controls.Control
              System.Windows.Controls.ContentControl
                 Derived Classes
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.