다음을 통해 공유


ContentControl.Content 속성

정의

ContentControl콘텐츠를 가져오거나 설정합니다.

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

속성 값

컨트롤의 콘텐츠를 포함하는 개체입니다. 기본값은 null입니다.

특성

예제

다음 예제에서는 다음 중 하나로 설정된 4개의 Button 컨트롤을 Content 만드는 방법을 보여 줍니다.

메모

예제의 XAML(Extensible Application Markup Language) 버전에서는 각 단추의 콘텐츠 주위에 태그를 사용할 <Button.Content> 수 있지만 필요하지는 않습니다. 자세한 내용은 XAML 개요 (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개의 단추를 보여 줍니다.

4개의 단추

설명

속성은 Content 형식 Object이므로 입력할 수 ContentControl있는 항목에 제한이 없습니다. 에 있는 /a0>에 의해 표시됩니다. WPF의 모든 ContentControl 형식에는 기본값ControlTemplateContentPresenter 있습니다. 표시되는 방법에 대한 자세한 내용은 다음을 ContentPresenter 참조하세요ContentContentPresenter.

종속성 속성 정보

Item 가치
식별자 필드 ContentProperty
메타데이터 속성이 다음으로 설정됩니다. true 없음

XAML 특성 사용

<object Content="content"/>

XAML 속성 요소 사용

<object> content</object>

XAML 값

Content 텍스트 또는 단일 개체입니다.

적용 대상