Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8706241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:34:04+00:00 2026-06-13T03:34:04+00:00

I want to display CustomerList\CustomerName property items to the ListBox using ItemsSource DisplayMemberPath property

  • 0

I want to display CustomerList\CustomerName property items to the ListBox using ItemsSource DisplayMemberPath property only. But it is not working. I do not want to use DataContext or any other binding in my problem. Please help.
My code is given below:

MainWindow.xaml.cs

namespace BindingAnItemControlToAList
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }

    public class Customer
    {
        public string Name {get;set;}
        public string LastName { get; set; }
    }
    public class CustomerList 
    { 
        public List<Customer> Customers { get; set; }
        public List<string> CustomerName { get; set; }
        public List<string> CustomerLastName { get; set; }
        public CustomerList() 
        { 
            Customers = new List<Customer>();
            CustomerName = new List<string>();
            CustomerLastName = new List<string>();
            CustomerName.Add("Name1");
            CustomerLastName.Add("LastName1");
            CustomerName.Add("Name2");
            CustomerLastName.Add("LastName2");

            Customers.Add(new Customer() { Name = CustomerName[0], LastName = CustomerLastName[0] });
            Customers.Add(new Customer() { Name = CustomerName[1], LastName = CustomerLastName[1] });
        } 
    } 
}

**MainWindow.Xaml**
<Window x:Class="BindingAnItemControlToAList.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:BindingAnItemControlToAList"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded" >
    <Window.Resources>
        <local:CustomerList x:Key="Cust"/>
    </Window.Resources>
    <Grid Name="Grid1">
        <ListBox ItemsSource="{Binding Source={StaticResource Cust}}"  DisplayMemberPath="CustomerName" Height="172" HorizontalAlignment="Left" Margin="27,23,0,0" Name="lstStates" VerticalAlignment="Top" Width="245" />
           </Grid>
</Window>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:34:06+00:00Added an answer on June 13, 2026 at 3:34 am

    Your’re not setting a “collection” as the ItemsSource…thus you don’t get anything to choose from. This will choose the list CustomerName.

    <ListBox ItemsSource="{Binding Source={StaticResource Cust}, Path=CustomerName}" 
        Height="172" HorizontalAlignment="Left" Margin="27,23,0,0" Name="lstStates" 
        VerticalAlignment="Top" Width="245" />
    

    But really, you should restructure your CustomerList class…there’s no need to have separate lists that copy the Name and LastName fields of the Customer – it means you are duplicating data unnecessarily, and also it’s possible for the data to get out of sync with each collection.

    You also should consider using INotifyPropertyChanged, and use INotifyCollectionChanged on your classes (e.g. use ObservableCollection instead of List, and implement INotifyPropertyChanged on the Customer class) if it’s possible to change the collection or data.

    e.g.

    public class CustomerList
    {
        public ObservableCollection<Customer> Customers { get; set; }
        public CustomerList()
        {
            Customers = new ObservableCollection<Customer>();
            Customers.Add(new Customer { Name = "Name1", LastName = "LastName1" });
            Customers.Add(new Customer { Name = "Name2", LastName = "LastName2" });
        }
    }
    
    <ListBox ItemsSource="{Binding Source={StaticResource Cust}, Path=Customers}" DisplayMemberPath="Name" Height="172" HorizontalAlignment="Left" Margin="27,23,0,0" Name="lstStates" VerticalAlignment="Top" Width="245" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want display data from database in Listbox...Here is my code, It is not
I want to display tabular type data, but it will not be coming from
Normally book module automatically generated book navigation but i want display only 2 book
I am not sure how to achieve this. I want to use a foreach
In a area of my UIView, i want display a UIImage, but the width
hi i am working for Twitter client, i want display number(NSNumber) on UILabel like
I want display error message in my view home.jsp using <c:out value=${message} /> .
Is it able to put views to the left, but off-screen? I want display
i am sending array list items[x,y,z...] to the custom adapter. i want display items
i want display 1 record from colums zodys , I'm programint in C# I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.