ItemsControl.DisplayMemberPath 属性


获取或设置源对象上的值的路径,以用作对象的可视表示形式。Gets or sets a path to a value on the source object to serve as the visual representation of the object.

 property System::String ^ DisplayMemberPath { System::String ^ get(); void set(System::String ^ value); };
public string DisplayMemberPath { get; set; }
member this.DisplayMemberPath : string with get, set
Public Property DisplayMemberPath As String



源对象上的值的路径。The path to a value on the source object. 这可以是任何路径,也可以是 XPath,如 " @Name "。This can be any path, or an XPath such as "@Name". 默认值为空字符串("")。The default is an empty string ("").



在下面的示例中,名为的静态资源 places 定义为对象的 Place 集合,其中每个 Place 对象都有一个 CityName 属性和一个 State 属性。In the following example, the static resource named places is defined as a collection of Place objects, in which each Place object has a CityName property and a State property. 前缀 src 映射到定义数据源的命名空间 PlacesThe prefix src is mapped to the namespace where the data source Places is defined. 前缀 scmdat 分别映射到 System.ComponentModelSystem.Windows.Data 命名空间。The prefixes scm and dat are mapped to the System.ComponentModel and System.Windows.Data namespaces, respectively.

下面的示例创建数据集合的视图,该视图按 city 名称进行排序并按状态分组。The following example creates a view of the data collection that is sorted by the city name and grouped by the state.


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

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

视图可以是绑定源,如以下示例中所示。The view can be a binding source, as in the following example. 由于指定的 DisplayMemberPath ,每个 Place 对象都显示为其 CityName 值。Because of the specified DisplayMemberPath, eachPlace object is shown with its CityName value. 如果 DisplayMemberPath 未指定,并且没有,则 DataTemplate 将在 ListBox 此示例中显示基础集合中每个对象的字符串表示形式 ("SDKSample" ) 。If DisplayMemberPath is not specified and there is no DataTemplate, then the ListBox displays a string representation of each object in the underlying collection (in this case, "SDKSample.Place").

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


此属性是定义描述如何显示数据对象的默认模板的一种简单方法。This property is a simple way to define a default template that describes how to display the data objects.

依赖项属性信息Dependency Property Information

标识符字段Identifier field DisplayMemberPathProperty
元数据属性设置为 trueMetadata properties set to true None