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)
The TemplatePartAttribute type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | TemplatePartAttribute | Initializes a new instance of the TemplatePartAttribute class |
| Name | Description | |
|---|---|---|
![]() ![]() | Equals | Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() | GetHashCode | Returns the hash code for this instance. (Inherited from Attribute.) |
![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | Match | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.) |
![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
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.
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.
<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>
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.



