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} 標記延伸來設定 Path。 如需完整的程式代碼清單,請參閱 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 資料系結範例

注意

(C++/CX) Visual C++ 元件延伸模組目前不支援索引子系結。 如需因應措施,請參閱範例。

<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 物件的屬性值。 如果您嘗試這樣做,將會收到運行時例外狀況。

適用於

另請參閱