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

プロパティ値

ソース オブジェクトの値へのパス。 任意のパス、または "@Name" などの XPath を指定できます。 既定値は空の文字列 ("") です。

属性

次の例では、 places という名前の静的リソースは、 Place オブジェクトのコレクションとして定義されています。各 Place オブジェクトには、 CityName プロパティと State プロパティがあります。 プレフィックス src は、データ ソース Places が定義されている名前空間にマップされます。 プレフィックス scmdat は、それぞれ 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>

注釈

このプロパティは、データ オブジェクトを表示する方法を説明する既定のテンプレートを定義する簡単な方法です。

依存関係プロパティ情報

品目 価値
識別子フィールド DisplayMemberPathProperty
に設定されたメタデータ プロパティ true None

適用対象

こちらもご覧ください