ItemsControl.DisplayMemberPath 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定路徑到來源物件的某個值,作為物件的視覺表示。
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
屬性值
指向來源物件值的路徑。 這可以是任何路徑,或是像「@Name」這樣的 XPath。 預設為空字串(“”)。
- 屬性
範例
在以下範例中,靜態資源被定義 places 為一組 Place 物件,每個 Place 物件擁有一個 CityName 屬性和一個 State 屬性。 前綴 src 會映射到定義資料來源 Places 的命名空間。 前綴 scm 和 dat 分別映射到 System.ComponentModel 和 System.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>
備註
這個屬性是一種簡單的方式,可以定義一個預設範本,用來描述如何顯示資料物件。
相依財產資訊
| Item | 價值觀 |
|---|---|
| 識別碼欄位 | DisplayMemberPathProperty |
元資料屬性設為 true |
None |