Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ItemsControl.DisplayMemberPath Property

Gets or sets the name or path of the property that is displayed for each data item.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
public string DisplayMemberPath { get; set; }
<itemsControl DisplayMemberPath="propertyPath"/>

XAML Values

propertyPath

A CLR property path. For details on the syntax for propertyPath, see Property Path Syntax.

Property Value

Type: System.String
The name or path of the property that is displayed for each the data item in the control. The default is an empty string ("").

Dependency property identifier field: DisplayMemberPathProperty

DisplayMemberPath can use a dotted path to reference subproperties of properties. For more information, see Data Binding.

The following example creates a ListBox, which inherits from ItemsControl, and binds it to a collection of Customer objects. The example sets the DisplayMemberPathProperty to the LastName property of the customer. Therefore, the ListBox displays the following values:

  • Anderberg

  • Ashton

  • Hicks

  • Pica


<Grid>
    <Grid.Resources>
        <src:Customers x:Key="customers"/>
    </Grid.Resources>
    <ListBox ItemsSource="{StaticResource customers}" Width="250" Margin="0,5,0,10" 
       DisplayMemberPath="LastName"/>
</Grid>


The following example shows the Customer class and the collection that the ListBox is bound to.


public class Customer
{
    public String FirstName { get; set; }
    public String LastName { get; set; }
    public String Address { get; set; }

    public Customer(String firstName, String lastName, String address)
    {
        this.FirstName = firstName;
        this.LastName = lastName;
        this.Address = address;
    }

}

public class Customers : ObservableCollection<Customer>
{
    public Customers()
    {
        Add(new Customer("Michael", "Anderberg",
                "12 North Third Street, Apartment 45"));
        Add(new Customer("Chris", "Ashton",
                "34 West Fifth Street, Apartment 67"));
        Add(new Customer("Cassie", "Hicks",
                "56 East Seventh Street, Apartment 89"));
        Add(new Customer("Guido", "Pica",
                "78 South Ninth Street, Apartment 10"));
    }

}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.