System.Windows.Controls Nam ...


.NET Framework Class Library for Silverlight
ContentControl Class

Represents a control with a single piece of content. Controls such as Button, CheckBox, and ScrollViewer directly or indirectly inherit from this class.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
Syntax

Visual Basic (Declaration)
<ContentPropertyAttribute("Content", True)> _
Public Class ContentControl _
    Inherits Control
Visual Basic (Usage)
Dim instance As ContentControl
C#
[ContentPropertyAttribute("Content", true)]
public class ContentControl : Control
XAML Object Element Usage
<ContentControl .../>
-or-
<contentControl>
  singleObject
</contentControl>

XAML Values

contentControl

A ContentControl object element, or an object element for a class that derives from ContentControl.

singleObject

A single object element that declares the content. Typically this is a class that can support further content as child elements, such as a Panel class.

Remarks

The Content property of a ContentControl can be any type of object, such as a string, a UIElement, or a DateTime. When Content is set to a UIElement, the UIElement is displayed in the ContentControl. When Content is set to another type of object, a string representation of the object is displayed in the ContentControl.

A ContentControl has a limited default style. If you want to enhance the appearance of the control, you can create a new DataTemplate.

Content Model: ContentControl is the class that other content controls inherit from. For more information, see Control Content Models.

Customizing the ContentControl Control

To apply the same property settings to multiple ContentControl controls, use the Style property. To change the visual structure and visual behavior of a ContentControl, copy and modify its default style and template. For more information, see Control Customization.

If a dependency property for a ContentControl is set by its default style, the property might change from its default value when the ContentControl appears in the application. For more information, see Dependency Property Value Precedence. You can get the default style and template for ContentControl from ContentControl Styles and Templates.

NoteNote:

Setting a visual property will only have an effect if that property is both present in ContentControl control's default template and is set by using a TemplateBinding. You can find a list of visual properties in the "Changing the Visual Structure of a Control" section of Customizing the Appearance of an Existing Control by Using a ControlTemplate.

Examples

The following example shows how to set different types of content for two Button controls and a CheckBox, which inherit from ContentControl.

Run this sample

XAML
<StackPanel Name="root" Width="200"  HorizontalAlignment="Center" VerticalAlignment="Center">

  <!--Create a Button with a string as its content.-->
  <Button Margin="10" Content="This is string content of a Button"/>

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

  <!--Create a Button with a panel that contains 
  multiple objects as its content.-->
  <CheckBox Margin="10">
    <StackPanel Margin="3,0,0,0" Orientation="Horizontal">
      <Ellipse Height="10" Width="10" Fill="Blue"/>
      <TextBlock TextAlignment="Center" Text="A string of text"></TextBlock>
    </StackPanel>
  </CheckBox>
</StackPanel>
Inheritance Hierarchy

System..::.Object
  System.Windows..::.DependencyObject
    System.Windows..::.UIElement
      System.Windows..::.FrameworkElement
        System.Windows.Controls..::.Control
          System.Windows.Controls..::.ContentControl
            System.Windows.Controls..::.ChildWindow
            System.Windows.Controls..::.DataGridCell
            System.Windows.Controls..::.Frame
            System.Windows.Controls..::.Label
            System.Windows.Controls..::.ListBoxItem
            System.Windows.Controls.Primitives..::.ButtonBase
            System.Windows.Controls.Primitives..::.DataGridColumnHeader
            System.Windows.Controls.Primitives..::.DataGridRowHeader
            System.Windows.Controls..::.ScrollViewer
            System.Windows.Controls..::.TabItem
            System.Windows.Controls..::.ToolTip
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

Other Resources

Tags :


Page view tracker