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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:22:32+00:00 2026-05-23T15:22:32+00:00

When I change a property in an item in a BindingList, the changes do

  • 0

When I change a property in an item in a BindingList, the changes do not propagate to the ListBox although the underlying object is changed.

public class MyClass : INotifyPropertyChanged
{
    public override string ToString()
    {
        return this.Name;
    }

    #region Name

    private string name;

    public string Name
    {
        get
        {
            return this.name;
        }

        set
        {
            if (value == this.name) return;

            this.name = value;
            this.OnPropertyChanged("Name");
        }
    }

    #endregion

    #region INotifyPropertyChanged event

    ///<summary>
    ///Occurs when a property value changes.
    ///</summary>
    public event PropertyChangedEventHandler PropertyChanged;


    /// <summary>
    /// Raises the <see cref="PropertyChanged"/> event for
    /// a given property.
    /// </summary>
    /// <param name="propertyName">The name of the changed property.</param>
    protected void OnPropertyChanged(string propertyName)
    {
        //validate the property name in debug builds
        VerifyProperty(propertyName);

        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }


    /// <summary>
    /// Verifies whether the current class provides a property with a given
    /// name. This method is only invoked in debug builds, and results in
    /// a runtime exception if the <see cref="OnPropertyChanged"/> method
    /// is being invoked with an invalid property name. This may happen if
    /// a property's name was changed but not the parameter of the property's
    /// invocation of <see cref="OnPropertyChanged"/>.
    /// </summary>
    /// <param name="propertyName">The name of the changed property.</param>
    [Conditional("DEBUG")]
    private void VerifyProperty(string propertyName)
    {
        Type type = this.GetType();

        //look for a *public* property with the specified name
        PropertyInfo pi = type.GetProperty(propertyName);
        if (pi == null)
        {
            //there is no matching property - notify the developer
            string msg = "OnPropertyChanged was invoked with invalid property name {0}: ";
            msg += "{0} is not a public property of {1}.";
            msg = String.Format(msg, propertyName, type.FullName);
            Debug.Fail(msg);
        }
    }

    #endregion
}

and the XAML

<Window x:Class="testBL.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <ListBox x:Name="myListBox">
        </ListBox>
        <Button x:Name="changeButton" Click="changeButton_Click">Change an item</Button>
    </StackPanel>
</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-05-23T15:22:33+00:00Added an answer on May 23, 2026 at 3:22 pm

    Because you are binding the ListBox to the collection, the default data context for each ListBoxItem is the instance. The collection for example is an ObservableCollection<MyClass> and the data context for each ListBoxItem is a MyClass instance.

    Since you haven’t provided a data template, the ListBoxItem is effectively bound to "{Binding}" which results in your MyClass.ToString() method being called. Since ToString() isn’t a property, it doesn’t support property change notification. Using binding in this way (binding to ToString()), only works for immutable objects.

    The solution is to provide an explicit binding for your ListBoxItem like this:

    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
    

    or to make your MyClass object immutable and replace them instead of mutating them.

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

Sidebar

Related Questions

If I change the ItemsSource property of a ListBox while an item is selected
I need to change a static property on an object in our web application.
I have a control mycontrol.ascx This control has a property: private GenericCollection<Item> myCollection; public
I have a class that represents some business object, such as this: Public Class
Both appear to create or change an item property. What's the difference between the
I have a ListBox that is bound to a ViewModel property of type BindingList(Of
I am new to PowerShell, I am trying to change a property of an
How to hook to the property value change notification for properties of a FrameworkElement?
I'm trying to change the IsEnabled property of a button if the validation on
Which property should I change on Info.plist in order to configure the list of

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.