ControlTemplate.TargetType Property

Gets or sets the type to which the ControlTemplate is applied.

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


Public Property TargetType As Type
public Type TargetType { get; set; }
<ControlTemplate TargetType="typeName"/>

XAML Values

  • typeName
    A string that specifies the type name of the type where the template is applied.

Property Value

Type: System.Type
The type to which the ControlTemplate is applied.


The Silverlight XAML processing behavior has special handling for property values that are of type Type. This behavior is to construct a Type instance as necessary based on its type name. You specify that name as the typeName attribute value as shown in the XAML syntax section. Note that {x:Type} is not supported in XAML for Silverlight 5 (you might have {x:Type} usages if you are migrating XAML). If you have {x:Type typeName} attribute values for TargetType, change them to just typeName.


The following example sets the TargetType property to Button to create a simple ControlTemplate for a Button.

<ControlTemplate TargetType="Button">
  <Grid >
      <VisualStateGroup x:Name="CommonStates">


          <!--Take one half second to trasition to the MouseOver state.-->
          <VisualTransition To="MouseOver" 

        <VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush, ButtonBrush, to red when the
            mouse is over the button.-->
        <VisualState x:Name="MouseOver">
            <ColorAnimation Storyboard.TargetName="ButtonBrush" 
                            Storyboard.TargetProperty="Color" To="Red" />
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>

Version Information


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.