WPF: Specify the property to display in ListBox

This entry is part 32 of 54 in the series Learn WPF

There are many ways to display data in a ListBox control.  As in the earlier example, we set the ItemsSource property to the collection we want to display.

Optionally, we can set the DisplayMemberPath to specify the property to display in the ListBox.

<Window x:Class="ListBoxNSpace.MainWindow"
        Title="MainWindow" Height="350" Width="525">
            <src:Customers x:Key="customers"/>
        <ListBox ItemsSource="{StaticResource customers}" Width="250" Margin="0,5,0,10" SelectedIndex="3"


using System;
using System.Collections.Generic;
using System.Windows;

namespace ListBoxNSpace
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>

    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"));
            Add(new Customer("Chris", "Ashton",
                    "34 West Fifth Street"));
            Add(new Customer("Cassie", "Hicks",
                    "56 East Seventh Street"));
            Add(new Customer("Guido", "Pica",
                    "78 South Ninth Street"));

    public partial class MainWindow : Window
        public MainWindow()



Series Navigation<< WPF: Changes in binding elements
WPF: Displaying more properties of a class in a ListBox >>