.NET Framework Class Library
ItemsControl..::.DisplayMemberPath Property

Gets or sets a path to a value on the source object to serve as the visual representation of the object. This is a dependency property.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Syntax

Visual Basic (Declaration)
<BindableAttribute(True)> _
Public Property DisplayMemberPath As String
Visual Basic (Usage)
Dim instance As ItemsControl
Dim value As String

value = instance.DisplayMemberPath

instance.DisplayMemberPath = value
C#
[BindableAttribute(true)]
public string DisplayMemberPath { get; set; }
Visual C++
[BindableAttribute(true)]
public:
property String^ DisplayMemberPath {
    String^ get ();
    void set (String^ value);
}
JScript
public function get DisplayMemberPath () : String
public function set DisplayMemberPath (value : String)
XAML Attribute Usage
<object DisplayMemberPath="string" .../>

Property Value

Type: System..::.String
The path to a value on the source object. This can be any path, or an XPath such as "@Name". The default is an empty string ("").
Dependency Property Information

Identifier field

DisplayMemberPathProperty

Metadata properties set to true

None

Remarks

This property is a simple way to define a default template that describes how to display the data objects.

Examples

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. The prefix src is mapped to the namespace where the data source Places is defined. The prefixes scm and dat are mapped to the System.ComponentModel and System.Windows.Data namespaces, respectively.

The following example creates a view of the data collection that is sorted by the city name and grouped by the state.

XAML
<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>

The view can be a binding source, as in the following example. Because of the specified DisplayMemberPath, eachPlace object is shown with its CityName value. 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").

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

For the complete example, see Sorting and Grouping Data in XAML Sample.

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Other Resources

Tags :


Page view tracker