Binding.Path プロパティ

定義

バインディング ソース プロパティへのパスを取得または設定します。

public:
 property PropertyPath ^ Path { PropertyPath ^ get(); void set(PropertyPath ^ value); };
PropertyPath Path();

void Path(PropertyPath value);
public PropertyPath Path { get; set; }
var propertyPath = binding.path;
binding.path = propertyPath;
Public Property Path As PropertyPath
<Binding Path="propertyPath"/>

プロパティ値

バインディングのソースのプロパティ パス。

次の XAML は、 {Binding} マークアップ拡張機能を使用してパスを設定する方法を示しています。 完全なコード一覧については、 XAML データ バインディングのサンプルを参照してください。

<StackPanel Margin="5">

  <TextBlock Text="Name:" Style="{StaticResource DescriptionTextStyle}" 
    Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>

  <TextBox Text="{Binding Path=Name, Mode=TwoWay}" 
    Width="350" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>

  <TextBlock Text="Organization:" Style="{StaticResource DescriptionTextStyle}" 
    Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>

  <!-- You can omit the 'Path=' portion of the binding expression. -->
  <TextBox Text="{Binding Organization, Mode=TwoWay}" Width="350" 
    Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top"/>

</StackPanel>

次の XAML は、整数および文字列インデクサーを使用して Path を設定する方法を示しています。 完全なコード一覧については、 XAML データ バインディングのサンプルを参照してください。

注意

Visual C++ コンポーネント拡張機能 (C++/CX) では、現在、インデクサー バインドはサポートされていません。 回避策については、サンプルを参照してください。

<StackPanel>

  <StackPanel Orientation="Horizontal">

    <TextBlock Text="Team name:" 
      Style="{StaticResource DescriptionTextStyle}" 
      Margin="5" FontWeight="Bold"/>

    <TextBlock Text="{Binding Path=[3].Name}" 
      Style="{StaticResource DescriptionTextStyle}" Margin="5" />

  </StackPanel>

  <StackPanel Orientation="Horizontal">

    <TextBlock Text="Team manager:" 
      Style="{StaticResource DescriptionTextStyle}" 
      Margin="5" FontWeight="Bold"/>

    <TextBlock Text="{Binding Path=[3][Gaffer]}" 
      Style="{StaticResource DescriptionTextStyle}" Margin="5"/>

  </StackPanel>

</StackPanel>

注釈

パスには、ソース オブジェクトの直接プロパティ、またはプロパティ パス構文を使用して走査するそのオブジェクトのサブプロパティを指定できます。 Microsoft .NET データ ソースの場合、パスはインデクサー構文を使用してコレクション内の特定の項目を参照することもできます。 プロパティ パスの形式の詳細については、「 プロパティ パスの構文」を参照してください。

データ ソースを Source オブジェクトに設定するには、パスを空の文字列 ("") で定義する必要があります。

{Binding} マークアップ拡張機能を使用する場合、Path 値は拡張機能の使用部分の直後にある引数を{Binding使用して設定できます。明示的に を含めるPath=必要はありません。 たとえば、 {Binding Albums} そのバインドの Path 値を、文字列 "Albums" から構築された PropertyPath に設定します (他の Binding プロパティは設定されません)。

Path のほとんどの使用方法には、その値の設定が含まれます。 既存のバインディングのプロパティを調べる値を取得するシナリオでは、 PropertyPath.Path 値にはパスを表す文字列が含まれます。

Binding オブジェクトのプロパティ値は、そのバインドがターゲット要素とターゲット プロパティにアタッチされた後は設定できません。 これを試みると、実行時例外が発生します。

適用対象

こちらもご覧ください