Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

ContentControl.Content Property

Gets or sets the value of the ContentControl dependency property.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
public Object Content { get; set; }
<contentControl>
  singleObject
</contentControl>
-or-
<contentControl>stringContent</contentControl>
<contentControl Content="stringContent"/>

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.

stringContent

A string that is the Content of the ContentControl. When you set the Content to a string in XAML, you must use the attribute value syntax.

Property Value

Type: System.Object
An object that contains the control's content. The default is null.

Dependency property identifier field: ContentProperty

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.

Content is the XAML content property of ContentPresenter and can thus support this content element syntax, as opposed to having to specify contentControl.Content as a property element.

Content Model: This property is used to set the content of controls that inherit from ContentControl and can be any object.

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

Run this sample


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


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.