Export (0) Print
Expand All

ContentControl.Content Property

Gets or sets the content of a ContentControl.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

[<BindableAttribute(true)>]
abstract Content : Object with get, set
[<BindableAttribute(true)>]
override Content : Object with get, set
<object> content</object>
<object Content="content"/>

XAML Values

Content

Text or a single object.

Property Value

Type: System.Object
An object that contains the control's content. The default value is a null reference (Nothing in Visual Basic).

Identifier field

ContentProperty

Metadata properties set to true

None

Because the Content property is of type Object, there are no restrictions on what you can put in a ContentControl. The Content is displayed by a ContentPresenter, which is in the ControlTemplate of the ContentControl. Every ContentControl type in WPF has a ContentPresenter in its default ControlTemplate. For more information about how the ContentPresenter displays Content, see ContentPresenter.

The following example demonstrates how to create four Button controls with Content set to one of the following:

NoteNote

Although the Extensible Application Markup Language (XAML) version of the example could use the <Button.Content> tags around the content of each button, it is not necessary. For more information, see XAML Overview (WPF).

<!--Create a Button with a string as its content.-->
<Button>This is string content of a Button</Button>

<!--Create a Button with a DateTime object as its content.-->
<Button xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <sys:DateTime>2004/3/4 13:6:55</sys:DateTime>
</Button>

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

<!--Create a Button with a panel that contains multiple objects 
as its content.-->
<Button>
  <StackPanel>
    <Ellipse Height="40" Width="40" Fill="Blue"/>
    <TextBlock TextAlignment="Center">Button</TextBlock>
  </StackPanel>
</Button>
No code example is currently available or this language may not be supported.

The following illustration shows the four buttons created in the previous example.

Four buttons

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft