ControlTemplate.TargetType プロパティ

定義

この ControlTemplate が対象としている型を取得または設定します。

public:
 property Type ^ TargetType { Type ^ get(); void set(Type ^ value); };
[System.Windows.Markup.Ambient]
public Type TargetType { get; set; }
[<System.Windows.Markup.Ambient>]
member this.TargetType : Type with get, set
Public Property TargetType As Type

プロパティ値

既定値は null です。

属性

例外

テンプレートの定義に TargetType が含まれている場合、ContentPresenter プロパティは null にすることができません。

指定された型が無効です。 TargetTypeControlTemplate は、ControlPage、または PageFunctionBase であるか、これらからの継承である必要があります。

次の例では、このプロパティの使用方法を示します。

<Style x:Key="{x:Type Label}"
       TargetType="Label">
  <Setter Property="HorizontalContentAlignment"
          Value="Left" />
  <Setter Property="VerticalContentAlignment"
          Value="Top" />
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="Label">
        <Border>
          <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            RecognizesAccessKey="True" />
        </Border>
        <ControlTemplate.Triggers>
          <Trigger Property="IsEnabled"
                   Value="false">
            <Setter Property="Foreground">
              <Setter.Value>
                <SolidColorBrush Color="{DynamicResource DisabledForegroundColor}" />
              </Setter.Value>
            </Setter>
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

上記の例では、次のリソースを使用します。

完全なサンプルについては、Styling with ControlTemplates Sampleを参照してください。

注釈

プロパティが型に設定されている resources セクションTargetTypeにスタンドアロンControlTemplateがある場合、 ControlTemplate は自動的にその型に適用されません。 代わりに、 を指定 x:Key し、テンプレートを明示的に適用する必要があります。

また、テンプレート定義に TargetTypeControlTemplate が含まれている ContentPresenter場合は、 プロパティが で必要であることにも注意してください。

XAML 属性の使用方法

<object  TargetType="typeName"/>  

XAML 値

typeName
クラスの型名。 クラスの名前を Type 参照するには、 マークアップ拡張機能と WPF XAML を使用します。

適用対象