EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

ItemsControl.DisplayMemberPath Property

May 11, 2014

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)
XMLNS for XAML: Not mapped to an xmlns.

'Déclaration
Public Property DisplayMemberPath As String
<itemsControl DisplayMemberPath="propertyPath"/>

XAML Values

propertyPath

A CLR property path.

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 for Windows Phone 8.

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
    Private _firstName As String
    Private _lastName As String
    Private _address As String

    Public Property FirstName() As String
        Get
            Return _firstName
        End Get

        Set(ByVal value As String)
            _firstName = value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return _lastName
        End Get

        Set(ByVal value As String)
            _lastName = value
        End Set
    End Property

    Public Property Address() As String
        Get
            Return _address
        End Get

        Set(ByVal value As String)
            _address = value
        End Set
    End Property

    Public Sub New(ByVal firstName As String, ByVal lastName As String, ByVal address As String)
        Me.FirstName = firstName
        Me.LastName = lastName
        Me.Address = address
    End Sub

End Class

Public Class Customers
    Inherits ObservableCollection(Of Customer)

    Public Sub New()
        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"))
    End Sub

End Class


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Afficher:
© 2014 Microsoft