ItemsControl.DisplayMemberPath 屬性

定義

取得或設定來源物件上值的路徑,以當作此物件的視覺表示。

public:
 property System::String ^ DisplayMemberPath { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public string DisplayMemberPath { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.DisplayMemberPath : string with get, set
Public Property DisplayMemberPath As String

屬性值

String

此來源物件上值的路徑。 這可以是任何路徑或 XPath,例如"@Name"。 預設為空字串 ("")。

屬性

範例

在下列範例中,名為 places 的靜態資源會定義為 物件的集合 Place ,其中每個 Place 物件都有 CityName 屬性和 State 屬性。 前置詞 src 會對應至定義資料來源 Places 的命名空間。 前置詞 scmdat 分別對應至 System.ComponentModelSystem.Windows.Data 命名空間。

下列範例會建立以城市名稱排序並依州/省分組的資料收集檢視。

<Window.Resources>

  <src:Places x:Key="places"/>

  <CollectionViewSource Source="{StaticResource places}" x:Key="cvs">
    <CollectionViewSource.SortDescriptions>
      <scm:SortDescription PropertyName="CityName"/>
    </CollectionViewSource.SortDescriptions>
    <CollectionViewSource.GroupDescriptions>
      <dat:PropertyGroupDescription PropertyName="State"/>
    </CollectionViewSource.GroupDescriptions>
  </CollectionViewSource>

檢視可以是系結來源,如下列範例所示。 由於指定的 DisplayMemberPath ,因此每個 Place 物件都會以其 CityName 值顯示。 如果未 DisplayMemberPath 指定 ,而且沒有 DataTemplate ,則 ListBox 會顯示基礎集合中每個物件的字串表示 (,在此案例中為 「SDKSample.Place」) 。

<ListBox ItemsSource="{Binding Source={StaticResource cvs}}"
         DisplayMemberPath="CityName" Name="lb">
  <ListBox.GroupStyle>
    <x:Static Member="GroupStyle.Default"/>
  </ListBox.GroupStyle>
</ListBox>

備註

這個屬性是定義預設範本的簡單方式,描述如何顯示資料物件。

相依性屬性資訊

識別碼欄位 DisplayMemberPathProperty
中繼資料屬性設定為 true

適用於

另請參閱