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

  • SEARCH
  • Home
  • 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 6047105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:18:53+00:00 2026-05-23T07:18:53+00:00

I have a ListBox and a class with strings. Each time that a user

  • 0

I have a ListBox and a class with strings. Each time that a user clicks add button in the application, I create a new instance of the class and add it to the list which is binded to the ListBox. The first time I click the add button, the list box shows the first item, but the next time it doesn’t show two items.

XAML – this is the ListBox:

<ListBox Name="ListBox_BinsRegion" Height="181" Margin="233,16,6,94" Width="253" Background="Transparent" BorderThickness="1" BorderBrush="Black" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemsSource="{Binding}"/> 

The code behind:

List<Class_ListViewItem> List_ListBoxItems = new List<Class_ListViewItem>();

 private void Button_Add_Click(object sender, RoutedEventArgs e)
    {
        Class_ListViewItem item = new Class_ListViewItem();
        item.WH = this.comboBox_WareHouseBinsRegionDefinition.SelectedItem.ToString();
        item.XXFrom = textBox_XXFrom.Text;
        item.XXTo = textBox_XXTo.Text;
        item.YYFrom = textBox_YYFrom.Text;
        item.YYTo = textBox_YYTO.Text;
        item.Z = textBox_ZFrom.Text;

        List_ListBoxItems.Add(item);

        ListBox_BinsRegion.DataContext = List_ListBoxItems;
    }

Where is my mistake?

  • 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-05-23T07:18:53+00:00Added an answer on May 23, 2026 at 7:18 am

    WPF does not know when your collection is changing. The problem is here:

    List<Class_ListViewItem> List_ListBoxItems = new List<Class_ListViewItem>();
    

    you need to change the list to

    ObservableCollection<Class_ListViewItem> List_ListBoxItems = new ObservableCollection<Class_ListViewItem>();
    

    ObservableCollection (System.Collections.ObjectModel) throws an event when the collection is changed, so that WPF can update the listbox.

    Also, you can remove the following line, or move it to the constructor of your control.

    ListBox_BinsRegion.DataContext = List_ListBoxItems;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox that displays Shipment Items (custom class) that are formatted using
in my Silverlight 4 application, I have a class myClass that contains a list
I have a WPF application, i created a new class named Agent . On
I have a List of Tasks that a user can preform. Each one will
I'm databinding a listbox to an object that contains two array of strings. Each
I have a control that we could identify as similar to ListBox control. Each
I have listbox and on click event I open new panel where i change
I have a ListBox that has a style defined for ListBoxItems. Inside this style,
I have a listbox that is databound to a Collection of objects. The listbox
I have a ListBox that when in focus, and when I have an item

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.