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 7692413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:50:49+00:00 2026-05-31T20:50:49+00:00

I am trying to create a list box that displays a set of data

  • 0

I am trying to create a list box that displays a set of data that will be updated over time. I have a simple list box:

<ListBox Name="lbRegisters" ItemsSource="{Binding}" />

And I have defined a class for my objects:

public class register : INotifyPropertyChanged

{
    private int address;
    public int Address { get { return address; } }

    private int value;
    public int Value
    {
        get{ return value; }
        set{
            this.value = value;

            OnValueChanged("Value");
        }
    }

    public register(int a)
    {
        address = a;
        value = 0;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void OnValueChanged(string name){
        if (PropertyChanged != null) 
            PropertyChanged(this, new PropertyChangedEventArgs(name));
    }

    public override string ToString()
    {
        return address + ": " + value;
    }
}

And I hold a list of these in an ObservableCollection<register>. Then set the ListBox.ItemsSource=registerslist; in the CodeBehind. The list is initialized and the inital data displays correctly.

Now what do I need to do to get my ListBox to update when a “register.Value” changes. The event handler is called but there nothing is subscribed to the event.

I guess I need to trigger something in the ListBox or ObservableCollection to tell the GUI to update. I have read dozens of posts of a similar problem but they all seem to indicate that once you have implemented INotofyPropertyChanged it just automagicaly works.

What is the next step?

  • 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-31T20:50:51+00:00Added an answer on May 31, 2026 at 8:50 pm

    The problem is on your ToString() function. Yes it could be used to display complex string in ListView items but it is not a proper way to bindings because ListView does not knows when part of this string was changed.

    Do the following:
    1. Declare property on register class like

        public string AddressValue
        {
            get { return address + ": " + value; }
        }
    

    2. Add OnValueChanged("AddressValue") in value and address setters like:

    public int Value
    {
        get{ return value; }
        set{
            this.value = value;
    
            OnValueChanged("Value");
            OnValueChanged("AddressValue")
        }
    }
    

    3. Declare you ListBox with ItemTemplate like:

        <ListBox x:Name="lbRegisters" ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                        <TextBlock  Text="{Binding AddressValue}"  />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    

    So the idea is adding new property to register class which will be updated when address and value changed. And bind list item text to this property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a list that adds a new row of data
I am trying to create a simple program that will allow the user to
I'm trying to create a control in wpf/xaml that will display a horizontal list
I am trying to create a simplified search box that will match multiple columns
I'm trying to create a Listbox that displays text and an image as one
I'm trying to create a list of tasks that I've read from some text
I'm trying to create a list that some of the elements are defined and
I have an the following class I'm trying to create a list of with
I'm trying to create a view that contains a list of checkboxes that is
I currently have a simple list view adapter that holds two rows of text.

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.