Content Property
Collapse the table of content
Expand the table of content

UserControl.Content Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets the content that is contained within a user control.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public UIElement Content { get; set; }
<UserControl ...>
<UserControl .../>

XAML Values


Exactly one object element for a class that derives from UIElement. This is almost always an object that can take child elements (such as a Panel) so that multiple elements can be added to content. XAML processing of a UserControl has a special behavior that sets this content to the otherwise protected Content property.

Property Value

Type: System.Windows.UIElement
The content of the user control.

Dependency property identifier field: ContentProperty

The XAML usage shown is special parsing handling of the otherwise protected Content property. When the partial classes of the UserControl subclass you define that serves as a page root are joined, the XAML content of the UserControl object element in page markup becomes the Content value of your page class, and the content of the loaded page in the application.

This following example creates a UserControl called NameReporter that asks for a name of a person, and reports it back to the user. The Content of NameReporter is a StackPanel. The TextBlock controls, TextBox controls, and Button are contained in the Children property of the StackPanel. For the complete example, see the UserControl class reference.

<phone:PhoneApplicationPage x:Class="UserControlExample.NameReporter"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" mc:Ignorable="d" xmlns:d="" xmlns:mc="" d:DesignHeight="800" d:DesignWidth="480">
  <StackPanel HorizontalAlignment="Center">

      <!--Create a Style for a TextBlock.-->
      <Style TargetType="TextBlock" x:Key="TextBlockStyle">
                <Setter Property="Foreground" Value="{StaticResource PhoneForegroundColor}"/>
        <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeSmall}"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Margin" Value="4"/>

      <!--Create a Style for a TextBlock.-->
      <Style TargetType="TextBox" x:Key="TextBoxStyle">
        <Setter Property="Width" Value="200"/>
                <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeSmall}"/>
                <Setter Property="Background" Value="{StaticResource PhoneForegroundColor}"/>

        <TextBlock FontSize="{StaticResource PhoneFontSizeSmall}" Text="Enter your name"/>
    <StackPanel Orientation="Horizontal">
           <TextBlock Style="{StaticResource TextBlockStyle}" Text="First Name:" />
           <TextBox Name="firstName" Style="{StaticResource TextBoxStyle}"/>
    <StackPanel Orientation="Horizontal">
            <TextBlock Style="{StaticResource TextBlockStyle}" Text="Last Name:" />

            <TextBox Name="lastName" Style="{StaticResource TextBoxStyle}"   />
    <Button  Content="Submit" Click="Button_Click"/>


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft