Binding.Path プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
バインディング ソース プロパティへのパスを取得または設定します。
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 は、整数インデクサーと文字列インデクサーを使用してパスを設定する方法を示しています。 完全なコード一覧については、 XAML データ バインディングのサンプルを参照してください。
<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} マークアップ拡張を使用する場合は、拡張機能の使用の{Binding部分の直後にある引数を使用して Path 値を設定できます。Path=を明示的に含める必要はありません。 たとえば、 {Binding Albums} は、そのバインドの Path 値を、文字列 "Albums" から構築された PropertyPath に設定します (他の Binding プロパティは設定されません)。
Path のほとんどの使用方法には、その値の設定が含まれます。 既存のバインディングのプロパティを調べる値を取得するシナリオでは、 PropertyPath.Path 値にはパスを表す文字列が含まれます。
バインドがターゲット要素とターゲット プロパティにアタッチされた後は、 Binding オブジェクトのプロパティ値を設定できません。 これを試みると、実行時の例外が発生します。