Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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 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 >
    <VisualStateManager.VisualStateGroups>
      <VisualStateGroup x:Name="CommonStates">

        <VisualStateGroup.Transitions>

          <!--Take one half second to trasition to the MouseOver state.-->
          <VisualTransition To="MouseOver" 
                              GeneratedDuration="0:0:0.5"/>
        </VisualStateGroup.Transitions>

        <VisualState x:Name="Normal" />

        <!--Change the SolidColorBrush, ButtonBrush, to red when the
            mouse is over the button.-->
        <VisualState x:Name="MouseOver">
          <Storyboard>
            <ColorAnimation Storyboard.TargetName="ButtonBrush" 
                            Storyboard.TargetProperty="Color" To="Red" />
          </Storyboard>
        </VisualState>
      </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Grid.Background>
      <SolidColorBrush x:Name="ButtonBrush" Color="Green"/>
    </Grid.Background>
  </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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft