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

정의

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

속성 값

컨트롤의 내용이 들어 있는 개체입니다.An object that contains the control's content. 기본값은 null입니다.The default value is null.

예제

다음 예제에는 4 개를 만드는 방법을 보여 줍니다 Button 사용 하 여 제어 Content 다음 중 하나로 설정 합니다.The following example demonstrates how to create four Button controls with Content set to one of the following:

참고

하지만 합니다 XAML(Extensible Application Markup Language)Extensible Application Markup Language (XAML) 버전의 예제를 사용할 수는 <Button.Content> 각 단추의 콘텐츠에 대 한 태그 필요는 없습니다.Although the 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. 자세한 내용은 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

다음 그림에서는 이전 예제에서 만든 4 개의 단추를 보여 줍니다.The following illustration shows the four buttons created in the previous example.

네 개의 단추가Four buttons

설명

때문에 Content 형식의 속성은 Object, 배치에 대 한 제한은 없습니다를 ContentControl입니다.Because the Content property is of type Object, there are no restrictions on what you can put in a ContentControl. Content 에 표시 되는 ContentPresenterControlTemplateContentControl합니다.The Content is displayed by a ContentPresenter, which is in the ControlTemplate of the ContentControl. 모든 ContentControl 입력 WPFWPFContentPresenter 기본값으로에서 ControlTemplate합니다.Every ContentControl type in WPFWPF has a ContentPresenter in its default ControlTemplate. 방법에 대 한 자세한 내용은 ContentPresenter 표시 Content를 참조 하세요 ContentPresenter합니다.For more information about how the ContentPresenter displays Content, see ContentPresenter.

종속성 속성 정보Dependency Property Information

식별자 필드Identifier field ContentProperty
메타 데이터 속성 설정 trueMetadata properties set to true 없음None

XAML 특성 사용XAML Attribute Usage

<object Content="content"/>  

XAML 속성 요소 사용XAML Property Element Usage

<object> content</object>  

XAML 값XAML Values

Content
텍스트 또는 단일 개체입니다.Text or a single object.

적용 대상