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数据源,路径还可以使用索引器语法来引用集合中的特定项。 有关属性路径格式的详细信息,请参阅 Property-path 语法。
若要将数据源设置为 Source 对象,应使用空字符串(“”)定义路径。
使用 {Binding} 标记扩展时,可以在扩展用法的一部分之后 {Binding 立即使用参数设置 Path 值,无需显式包含 Path=。 例如, {Binding Albums} 将该绑定的路径值设置为从字符串“Albums”构造的 PropertyPath (未设置其他 绑定 属性)。
路径的大多数用法都涉及设置其值。 对于获取用于检查现有绑定属性的值的方案, PropertyPath.Path 值包含表示路径的字符串。
绑定已附加到目标元素和目标属性后,无法设置 Binding 对象的属性值。 如果尝试此操作,则会出现运行时异常。