Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Silverlight 2

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 2

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
ContentControl Class

Represents a control with a single piece of content. Controls such as Button, CheckBox, and ScrollViewer directly or indirectly inherit from this class.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
<ContentPropertyAttribute("Content", True)> _
Public Class ContentControl _
    Inherits Control
Visual Basic (Usage)
Dim instance As ContentControl
C#
[ContentPropertyAttribute("Content", true)]
public class ContentControl : Control
XAML Object Element Usage
<ContentControl .../>
-or-
<contentControl>
  singleObject
</contentControl>

XAML Values

contentControl

A ContentControl object element, or an object element for a class that derives from ContentControl.

singleObject

A single object element that declares the content. Typically this is a class that can support further content as child elements, such as a Panel class.

The Content property of a ContentControl can be any type of object, such as a string, a UIElement, or a DateTime. When Content is set to a UIElement, the UIElement is displayed in the ContentControl. When Content is set to another type of object, a string representation of the object is displayed in the ContentControl.

A ContentControl has a limited default style. If you want to enhance the appearance of the control, you can create a new DataTemplate.

Content Model: ContentControl is the class that other content controls inherit from. For more information, see Control Content Models.

The following example shows how to set different types of content for two Button controls and a CheckBox, which inherit from ContentControl.

<StackPanel Name="root" Width="200"  HorizontalAlignment="Center" VerticalAlignment="Center">

  <!--Create a Button with a string as its content.-->
  <Button Margin="10" Content="This is string content of a Button"/>

  <!--Create a Button with a single UIElement as its content.-->
  <Button Margin="10">
    <Rectangle Height="40" Width="40" Fill="Blue"/>
  </Button>

  <!--Create a Button with a panel that contains 
  multiple objects as its content.-->
  <CheckBox Margin="10">
    <StackPanel Margin="3,0,0,0" Orientation="Horizontal">
      <Ellipse Height="10" Width="10" Fill="Blue"/>
      <TextBlock TextAlignment="Center" Text="A string of text"></TextBlock>
    </StackPanel>
  </CheckBox>
</StackPanel>

Run this sample.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker