TemplateBindingExtension クラス

定義

テンプレート内のプロパティ値と、template 宣言されたコントロールで公開されているその他のプロパティ値の間におけるバインディングをサポートするマークアップ拡張機能を実装します。

public ref class TemplateBindingExtension : System::Windows::Markup::MarkupExtension
[System.ComponentModel.TypeConverter(typeof(System.Windows.TemplateBindingExtensionConverter))]
public class TemplateBindingExtension : System.Windows.Markup.MarkupExtension
[System.ComponentModel.TypeConverter(typeof(System.Windows.TemplateBindingExtensionConverter))]
[System.Windows.Markup.MarkupExtensionReturnType(typeof(System.Object))]
public class TemplateBindingExtension : System.Windows.Markup.MarkupExtension
[<System.ComponentModel.TypeConverter(typeof(System.Windows.TemplateBindingExtensionConverter))>]
type TemplateBindingExtension = class
    inherit MarkupExtension
[<System.ComponentModel.TypeConverter(typeof(System.Windows.TemplateBindingExtensionConverter))>]
[<System.Windows.Markup.MarkupExtensionReturnType(typeof(System.Object))>]
type TemplateBindingExtension = class
    inherit MarkupExtension
Public Class TemplateBindingExtension
Inherits MarkupExtension
継承
TemplateBindingExtension
属性

次の例は、 ControlTemplate 水平で角が丸い を ListBox 定義する を示しています。 はTemplateBinding、 の を BackgroundBorderListBox設定されている値とBackground同期する必要があることを示します。 コントロールのユーザーに特定のプロパティの値を制御させる場合は、 で ControlTemplate を使用TemplateBindingします。 この例の説明については、「 スタイル設定とテンプレート」を参照してください。

<Style TargetType="ListBox">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="ListBox">
        <Border CornerRadius="5" Background="{TemplateBinding ListBox.Background}">
          <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <StackPanel Orientation="Horizontal"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"
                       IsItemsHost="True"/>
          </ScrollViewer>
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

次の例は、 ControlTemplate コントロールの を Label 示しています。 HorizontalAlignmentプロパティと VerticalAlignment プロパティは、これがControlTemplate適用されるコントロールの HorizontalContentAlignment および VerticalContentAlignment プロパティのLabel値にバインドされます。

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

注釈

テンプレートで を使用 TemplateBinding して、テンプレートが適用されるコントロールの値にバインドします。 TemplateBindingは よりもBinding効率的ですが、機能は少なくなります。 をTemplateBinding使用することは、 プロパティを に設定して をBindingRelativeSource使用することとRelativeSource.TemplatedParent同じです。

XAML テキストの使用法

XAML の詳細については、「 TemplateBinding Markup Extension」を参照してください。

コンストラクター

TemplateBindingExtension()

TemplateBindingExtension クラスの新しいインスタンスを初期化します。

TemplateBindingExtension(DependencyProperty)

バインディングのソースになっている依存関係プロパティが指定された、TemplateBindingExtension クラスの新しいインスタンスを初期化します。

プロパティ

Converter

バインディングのソースとターゲットの間で解釈を行うコンバーターを取得または設定します。

ConverterParameter

コンバーターに渡すパラメーターを取得または設定します。

Property

バインドされるプロパティを取得または設定します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ProvideValue(IServiceProvider)

このマークアップ拡張機能で使用するターゲット オブジェクトのプロパティ上の値として設定するオブジェクトを返します。 TemplateBindingExtension の場合は、バインディングをサポートする、式 (TemplateBindingExpression) になります。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象