Export (0) Print
Expand All

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.

System.Object
  System.Attribute
    System.Windows.TemplatePartAttribute

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

[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true)]
public sealed class TemplatePartAttribute : Attribute

The TemplatePartAttribute type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneTemplatePartAttributeInitializes a new instance of the TemplatePartAttribute class
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneNameGets or sets a string that reports the object model name of a template part.
Public propertySupported by Silverlight for Windows PhoneTypeGets or sets a string that reports the Type of a template part.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneEqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected methodSupported by Silverlight for Windows PhoneFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public methodSupported by Silverlight for Windows PhoneGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneMatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodSupported by Silverlight for Windows PhoneMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.


[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.


<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>


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

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

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

Community Additions

ADD
Show:
© 2014 Microsoft