War diese Seite hilfreich?
Ihr Feedback ist uns wichtig. Teilen Sie uns Ihre Meinung mit.
Weiteres Feedback?
1500 verbleibende Zeichen
Exportieren (0) Drucken
Alle erweitern

ContentPresenter-Klasse

Displays the content of a ContentControl.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML-Namespaces:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)] 
public class ContentPresenter : FrameworkElement
/** @attribute LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable) */ 
public class ContentPresenter extends FrameworkElement
LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable) 
public class ContentPresenter extends FrameworkElement

Typically, when you would use the ContentPresenter directly is within the ControlTemplate of a ContentControl to mark where the content is to be added.

Every ContentControl type has a ContentPresenter within its ControlTemplate. The ContentPresenter is responsible for the UI generation. For example, when you apply a DataTemplate to an ItemsControl such as a ListBox, behind the scenes it is actually the ContentPresenter within the ListBoxItem that creates the UI of each item. For more information about that particular example, see ItemTemplate.

The following shows a Button Style that sets the ControlTemplate of a Button. The ControlTemplate defines that the Button appears as an Ellipse within a Grid element. The ContentPresenter marks that the Content of the Button should be displayed and centered vertically and horizontally within the Grid.

<Style TargetType="Button">
  <!--Set to true to not get any properties from the themes.-->
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Button">
        <Grid>
          <Ellipse Fill="{TemplateBinding Background}"/>
          <ContentPresenter HorizontalAlignment="Center"
                            VerticalAlignment="Center"/>
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

The following image shows the appearance of the Button when this gets applied:

Button ControlTemplate sample

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
            System.Windows.Controls.ContentPresenter
               System.Windows.Controls.ScrollContentPresenter

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Microsoft .NET Framework 3.0 wird unter Windows Vista, Microsoft Windows XP SP2 und Windows Server 2003 SP1 unterstützt.

.NET Framework

Unterstützt in: 3.0
Anzeigen:
© 2015 Microsoft