ContentControl.Content ContentControl.Content ContentControl.Content ContentControl.Content Property

Definición

Obtiene o establece el contenido de ContentControl.Gets or sets the content of a ContentControl.

public:
 property System::Object ^ Content { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.Bindable(true)]
public object Content { get; set; }
member this.Content : obj with get, set
Public Property Content As Object

Valor de propiedad

Objeto que contiene el contenido del control. An object that contains the control's content. El valor predeterminado es null.The default value is null.

Ejemplos

En el ejemplo siguiente se muestra cómo crear cuatro Button controla con Content establecido en uno de los siguientes:The following example demonstrates how to create four Button controls with Content set to one of the following:

Nota

Aunque el Lenguaje XAML (Extensible Application Markup Language)Extensible Application Markup Language (XAML) versión del ejemplo se podría utilizar el <Button.Content> etiquetas en torno al contenido de cada botón, no es necesario.Although the Lenguaje XAML (Extensible Application Markup Language)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. Para obtener más información, consulte información general sobre XAML (WPF).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>
// Create a Button with a string as its content.
Button stringContent = new Button();
stringContent.Content = "This is string content of a Button";

// Create a Button with a DateTime object as its content.
Button objectContent = new Button();
DateTime dateTime1 = new DateTime(2004, 3, 4, 13, 6, 55);

objectContent.Content = dateTime1;

// Create a Button with a single UIElement as its content.
Button uiElementContent = new Button();

Rectangle rect1 = new Rectangle();
rect1.Width = 40;
rect1.Height = 40;
rect1.Fill = Brushes.Blue;
uiElementContent.Content = rect1;

// Create a Button with a panel that contains multiple objects 
// as its content.
Button panelContent = new Button();
StackPanel stackPanel1 = new StackPanel();
Ellipse ellipse1 = new Ellipse();
TextBlock textBlock1 = new TextBlock();

ellipse1.Width = 40;
ellipse1.Height = 40;
ellipse1.Fill = Brushes.Blue;

textBlock1.TextAlignment = TextAlignment.Center;
textBlock1.Text = "Button";

stackPanel1.Children.Add(ellipse1);
stackPanel1.Children.Add(textBlock1);

panelContent.Content = stackPanel1;
' Add a string to a button.
Dim stringContent As New Button()
stringContent.Content = "This is string content of a Button"

' Add a DateTime object to a button.
Dim objectContent As New Button()
Dim dateTime1 As New DateTime(2004, 3, 4, 13, 6, 55)

objectContent.Content = dateTime1

' Add a single UIElement to a button.
Dim uiElementContent As New Button()

Dim rect1 As New Rectangle()
rect1.Width = 40
rect1.Height = 40
rect1.Fill = Brushes.Blue
uiElementContent.Content = rect1

' Add a panel that contains multpile objects to a button.
Dim panelContent As New Button()
Dim stackPanel1 As New StackPanel()
Dim ellipse1 As New Ellipse()
Dim textBlock1 As New TextBlock()

ellipse1.Width = 40
ellipse1.Height = 40
ellipse1.Fill = Brushes.Blue

textBlock1.TextAlignment = TextAlignment.Center
textBlock1.Text = "Button"

stackPanel1.Children.Add(ellipse1)
stackPanel1.Children.Add(textBlock1)

panelContent.Content = stackPanel1

La ilustración siguiente muestra los cuatro botones que creó en el ejemplo anterior.The following illustration shows the four buttons created in the previous example.

Cuatro botonesFour buttons

Comentarios

Dado que el Content propiedad es de tipo Object, no hay ninguna restricción sobre lo que se puede colocar un ContentControl.Because the Content property is of type Object, there are no restrictions on what you can put in a ContentControl. El Content se muestra mediante un ContentPresenter, que se encuentra en el ControlTemplate de la ContentControl.The Content is displayed by a ContentPresenter, which is in the ControlTemplate of the ContentControl. Cada ContentControl escriba WPFWPF tiene un ContentPresenter en su valor predeterminado ControlTemplate.Every ContentControl type in WPFWPF has a ContentPresenter in its default ControlTemplate. Para obtener más información acerca de cómo los ContentPresenter muestra Content, consulte ContentPresenter.For more information about how the ContentPresenter displays Content, see ContentPresenter.

Información sobre propiedades de dependenciaDependency Property Information

Campo de identificadorIdentifier field ContentProperty
Establecen las propiedades de metadatos en trueMetadata properties set to true NoneNone

Uso de atributos XAMLXAML Attribute Usage

<object Content="content"/>  

Uso de elementos de propiedad XAMLXAML Property Element Usage

<object> content</object>  

Valores XAMLXAML Values

Content
Texto o un único objeto.Text or a single object.

Se aplica a