Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
TemplatePartAttribute Class

Represents an attribute that is applied to the class definition to identify the types of the named parts that are used for control templating.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple := True)> _
Public NotInheritable Class TemplatePartAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As TemplatePartAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true)]
public sealed class TemplatePartAttribute : Attribute

Control authors apply this attribute to the class definition of a control class to inform template authors what elements the control expects to find in its ControlTemplate. These parts must have the name specified by the Name property in order to properly interact with the control's constructor and run-time logic. There can only be one element with a given name in any template.

The following example shows TemplatePartAttribute objects that are defined on the definition of the ComboBox class.

Visual Basic
<TemplatePartAttribute(Name:="ContentPresenter", Type:=GetType(ContentPresenter))> _
<TemplatePartAttribute(Name:="Popup", Type:=GetType(Popup))> _
Public Class ComboBox
    Inherits ItemsControl

End Class
C#
[TemplatePartAttribute(Name = "ContentPresenter", Type = typeof(ContentPresenter))]
[TemplatePartAttribute(Name = "Popup", Type = typeof(Popup))]
public class ComboBox : ItemsControl
{
}

The following example shows a simplified ControlTemplate for the ComboBox that includes the elements that are specified by the TemplatePartAttribute objects on the ComboBox class.

XAML
<ControlTemplate TargetType="ComboBox">
  <Grid>
    <Border x:Name="ContentPresenterBorder">
      <Grid>
        <ToggleButton x:Name="DropDownToggle"
                      HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  
                      Margin="-1" HorizontalContentAlignment="Right">
          <Path x:Name="BtnArrow" Height="4" Width="8" 
                Stretch="Uniform" Margin="0,0,6,0"  Fill="Black"
                Data="F1 M 300,-190L 310,-190L 305,-183L 301,-190 Z " />
        </ToggleButton>
        <ContentPresenter x:Name="ContentPresenter" Margin="6,2,25,2">
          <TextBlock Text=" " />
        </ContentPresenter>
      </Grid>
    </Border>
    <Popup x:Name="Popup">
      <Border x:Name="PopupBorder" 
              HorizontalAlignment="Stretch" Height="Auto" 
              BorderThickness="{TemplateBinding BorderThickness}" 
              BorderBrush="Black" Background="White" CornerRadius="3">
        <ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1">
          <ItemsPresenter/>
        </ScrollViewer>
      </Border>
    </Popup>

  </Grid>
</ControlTemplate>
System..::.Object
  System..::.Attribute
    System.Windows..::.TemplatePartAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker