WPF Adding an item to a BindingList not update another Property in Viewmodel












0















I have this code in my viewmodel (Singleton):



    /// <summary>
/// Gets or sets the person list.
/// </summary>
/// <value>
/// The person list.
/// </value>
public BindingList<Person> PersonList
{
get { return personList; }
set
{
personList = value;
OnPropertyChanged(nameof(PersonList));
OnPropertyChanged(nameof(PersonCount));
}
}

/// <summary>
/// Gets the person count.
/// </summary>
/// <value>
/// The person count.
/// </value>
public int PersonCount
{
get
{
return personList.Count();
}
}


When I add a Person to the BindingList it appears in the view correctly. A Change of one of the items of BindingList is shown correctly.
But the PersonCount is not updated and appears as "0".



The class Person is implemented like this:



public class Person : NotificationObject
{
#region Fields

private string name;
private DateTime birthDate;
private string lastName;

#endregion // Fields

#region Construction
#endregion // Construction

#region Attributes

public string Name
{
get { return name; }
set
{
name = value;
OnPropertyChanged(nameof(Name));
}
}

public string LastName
{
get { return lastName; }
set
{
lastName = value;
OnPropertyChanged(nameof(LastName));
}
}

public DateTime BirthDate
{
get { return birthDate; }
set
{
birthDate = value;
OnPropertyChanged(nameof(BirthDate));
OnPropertyChanged(nameof(Age));
}
}

public int Age
{
get { return (DateTime.Now - birthDate).Days/365; }
}

#endregion // Attributes

#region Operations
#endregion // Operations

#region Implementation
#endregion // Implementation
} // class Person


Why the PersonCount is not updated and how to do it right?
What I am doing wrong?



Thanks in advance,
Andreas










share|improve this question





























    0















    I have this code in my viewmodel (Singleton):



        /// <summary>
    /// Gets or sets the person list.
    /// </summary>
    /// <value>
    /// The person list.
    /// </value>
    public BindingList<Person> PersonList
    {
    get { return personList; }
    set
    {
    personList = value;
    OnPropertyChanged(nameof(PersonList));
    OnPropertyChanged(nameof(PersonCount));
    }
    }

    /// <summary>
    /// Gets the person count.
    /// </summary>
    /// <value>
    /// The person count.
    /// </value>
    public int PersonCount
    {
    get
    {
    return personList.Count();
    }
    }


    When I add a Person to the BindingList it appears in the view correctly. A Change of one of the items of BindingList is shown correctly.
    But the PersonCount is not updated and appears as "0".



    The class Person is implemented like this:



    public class Person : NotificationObject
    {
    #region Fields

    private string name;
    private DateTime birthDate;
    private string lastName;

    #endregion // Fields

    #region Construction
    #endregion // Construction

    #region Attributes

    public string Name
    {
    get { return name; }
    set
    {
    name = value;
    OnPropertyChanged(nameof(Name));
    }
    }

    public string LastName
    {
    get { return lastName; }
    set
    {
    lastName = value;
    OnPropertyChanged(nameof(LastName));
    }
    }

    public DateTime BirthDate
    {
    get { return birthDate; }
    set
    {
    birthDate = value;
    OnPropertyChanged(nameof(BirthDate));
    OnPropertyChanged(nameof(Age));
    }
    }

    public int Age
    {
    get { return (DateTime.Now - birthDate).Days/365; }
    }

    #endregion // Attributes

    #region Operations
    #endregion // Operations

    #region Implementation
    #endregion // Implementation
    } // class Person


    Why the PersonCount is not updated and how to do it right?
    What I am doing wrong?



    Thanks in advance,
    Andreas










    share|improve this question



























      0












      0








      0








      I have this code in my viewmodel (Singleton):



          /// <summary>
      /// Gets or sets the person list.
      /// </summary>
      /// <value>
      /// The person list.
      /// </value>
      public BindingList<Person> PersonList
      {
      get { return personList; }
      set
      {
      personList = value;
      OnPropertyChanged(nameof(PersonList));
      OnPropertyChanged(nameof(PersonCount));
      }
      }

      /// <summary>
      /// Gets the person count.
      /// </summary>
      /// <value>
      /// The person count.
      /// </value>
      public int PersonCount
      {
      get
      {
      return personList.Count();
      }
      }


      When I add a Person to the BindingList it appears in the view correctly. A Change of one of the items of BindingList is shown correctly.
      But the PersonCount is not updated and appears as "0".



      The class Person is implemented like this:



      public class Person : NotificationObject
      {
      #region Fields

      private string name;
      private DateTime birthDate;
      private string lastName;

      #endregion // Fields

      #region Construction
      #endregion // Construction

      #region Attributes

      public string Name
      {
      get { return name; }
      set
      {
      name = value;
      OnPropertyChanged(nameof(Name));
      }
      }

      public string LastName
      {
      get { return lastName; }
      set
      {
      lastName = value;
      OnPropertyChanged(nameof(LastName));
      }
      }

      public DateTime BirthDate
      {
      get { return birthDate; }
      set
      {
      birthDate = value;
      OnPropertyChanged(nameof(BirthDate));
      OnPropertyChanged(nameof(Age));
      }
      }

      public int Age
      {
      get { return (DateTime.Now - birthDate).Days/365; }
      }

      #endregion // Attributes

      #region Operations
      #endregion // Operations

      #region Implementation
      #endregion // Implementation
      } // class Person


      Why the PersonCount is not updated and how to do it right?
      What I am doing wrong?



      Thanks in advance,
      Andreas










      share|improve this question
















      I have this code in my viewmodel (Singleton):



          /// <summary>
      /// Gets or sets the person list.
      /// </summary>
      /// <value>
      /// The person list.
      /// </value>
      public BindingList<Person> PersonList
      {
      get { return personList; }
      set
      {
      personList = value;
      OnPropertyChanged(nameof(PersonList));
      OnPropertyChanged(nameof(PersonCount));
      }
      }

      /// <summary>
      /// Gets the person count.
      /// </summary>
      /// <value>
      /// The person count.
      /// </value>
      public int PersonCount
      {
      get
      {
      return personList.Count();
      }
      }


      When I add a Person to the BindingList it appears in the view correctly. A Change of one of the items of BindingList is shown correctly.
      But the PersonCount is not updated and appears as "0".



      The class Person is implemented like this:



      public class Person : NotificationObject
      {
      #region Fields

      private string name;
      private DateTime birthDate;
      private string lastName;

      #endregion // Fields

      #region Construction
      #endregion // Construction

      #region Attributes

      public string Name
      {
      get { return name; }
      set
      {
      name = value;
      OnPropertyChanged(nameof(Name));
      }
      }

      public string LastName
      {
      get { return lastName; }
      set
      {
      lastName = value;
      OnPropertyChanged(nameof(LastName));
      }
      }

      public DateTime BirthDate
      {
      get { return birthDate; }
      set
      {
      birthDate = value;
      OnPropertyChanged(nameof(BirthDate));
      OnPropertyChanged(nameof(Age));
      }
      }

      public int Age
      {
      get { return (DateTime.Now - birthDate).Days/365; }
      }

      #endregion // Attributes

      #region Operations
      #endregion // Operations

      #region Implementation
      #endregion // Implementation
      } // class Person


      Why the PersonCount is not updated and how to do it right?
      What I am doing wrong?



      Thanks in advance,
      Andreas







      c# wpf mvvm bindinglist






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 4 '18 at 9:00









      Rekshino

      2,7861728




      2,7861728










      asked Nov 23 '18 at 10:54









      Andreas SusewindAndreas Susewind

      234




      234
























          2 Answers
          2






          active

          oldest

          votes


















          1














          The problem in your code is, once you bind the 'PersonList' to the view model, the list object doesn't change unless you bind another list (what happens is just items are added or removed from the list), therefore the setter of the 'PersonList' property is not called & therefore "Notify property changed" doesn't trigger for 'PersonCount'.



          However as the 'PersonList' is a BindingList, added/removed items are reflected in the UI.



          Solutions



          1) Register 'PersonList' to ListChanged event and call 'Notify Property Changed' in the event handler.



              public BindingList<Person> PersonList
          {
          get { return personList; }
          set
          {
          if (personList != null)
          personList.ListChanged -= PersonList_ListChanged;

          personList = value;

          if (personList != null)
          personList.ListChanged += PersonList_ListChanged;

          OnPropertyChanged(nameof(PersonList));
          }
          }

          public PersonsDashboardViewModel()
          {
          PersonList = new BindingList<Person>();

          PersonList.Add(new Person("Name1", "Lname1"));
          PersonList.Add(new Person("Name2", "Lname2"));
          }

          private void PersonList_ListChanged(object sender, ListChangedEventArgs e)
          {
          OnPropertyChanged(nameof(PersonCount));
          }


          OR



          2) Call 'Notify Property Changed' for 'PersonCount' where you add person items.



              public void AddPersonItem()
          {
          PersonList.Add(new Person("Sean", "Brendon"));
          OnPropertyChanged(nameof(PersonCount));
          }





          share|improve this answer





















          • 2





            Your point 1) is dangerous! If you set PersonList one more time not in the constructor of PersonsDashboardViewModel the UI will not be updated. You have to more attentively read my answer

            – Rekshino
            Nov 23 '18 at 12:07











          • Your first solution did the work. I use a separate class with BusinessLogic to alter the viewmodel. The OnPropertyChanged method is private, too. Because of this I can`t use the OnPropertyChanged-Method of the viewmodel in this BusinessLogic.

            – Andreas Susewind
            Nov 23 '18 at 12:11











          • Agreed with @Rekshino , you have to be careful when registering events. Registering for the 'ListChanged' event in the setter of 'PersonList' is straightforward.

            – Praboda
            Nov 23 '18 at 13:25











          • Now it looks out better.

            – Rekshino
            Nov 26 '18 at 7:34



















          2














          You have to invoke OnPropertyChanged(nameof(PersonCount)); where you modify the list. If it's not possible, then you have to subscribe to CollectionChanged for PersonList in setter and invoke OnPropertyChanged(nameof(PersonCount)); in event handler.






          share|improve this answer
























          • Thank you for your answer. My Personlist is instantiated in the constructor respectively in a reset-method to reset the viewmodel if needed. Is it what you mean with "in setter" ? Thanks in advance.

            – Andreas Susewind
            Nov 23 '18 at 14:44






          • 1





            @AndreasSusewind If you reassign the list in the reset method, then you have to unsubscribe the previous event handler and set the new one. Praboda has changed the answer, now is subscription in setter.

            – Rekshino
            Nov 26 '18 at 7:27











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445315%2fwpf-adding-an-item-to-a-bindinglist-not-update-another-property-in-viewmodel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The problem in your code is, once you bind the 'PersonList' to the view model, the list object doesn't change unless you bind another list (what happens is just items are added or removed from the list), therefore the setter of the 'PersonList' property is not called & therefore "Notify property changed" doesn't trigger for 'PersonCount'.



          However as the 'PersonList' is a BindingList, added/removed items are reflected in the UI.



          Solutions



          1) Register 'PersonList' to ListChanged event and call 'Notify Property Changed' in the event handler.



              public BindingList<Person> PersonList
          {
          get { return personList; }
          set
          {
          if (personList != null)
          personList.ListChanged -= PersonList_ListChanged;

          personList = value;

          if (personList != null)
          personList.ListChanged += PersonList_ListChanged;

          OnPropertyChanged(nameof(PersonList));
          }
          }

          public PersonsDashboardViewModel()
          {
          PersonList = new BindingList<Person>();

          PersonList.Add(new Person("Name1", "Lname1"));
          PersonList.Add(new Person("Name2", "Lname2"));
          }

          private void PersonList_ListChanged(object sender, ListChangedEventArgs e)
          {
          OnPropertyChanged(nameof(PersonCount));
          }


          OR



          2) Call 'Notify Property Changed' for 'PersonCount' where you add person items.



              public void AddPersonItem()
          {
          PersonList.Add(new Person("Sean", "Brendon"));
          OnPropertyChanged(nameof(PersonCount));
          }





          share|improve this answer





















          • 2





            Your point 1) is dangerous! If you set PersonList one more time not in the constructor of PersonsDashboardViewModel the UI will not be updated. You have to more attentively read my answer

            – Rekshino
            Nov 23 '18 at 12:07











          • Your first solution did the work. I use a separate class with BusinessLogic to alter the viewmodel. The OnPropertyChanged method is private, too. Because of this I can`t use the OnPropertyChanged-Method of the viewmodel in this BusinessLogic.

            – Andreas Susewind
            Nov 23 '18 at 12:11











          • Agreed with @Rekshino , you have to be careful when registering events. Registering for the 'ListChanged' event in the setter of 'PersonList' is straightforward.

            – Praboda
            Nov 23 '18 at 13:25











          • Now it looks out better.

            – Rekshino
            Nov 26 '18 at 7:34
















          1














          The problem in your code is, once you bind the 'PersonList' to the view model, the list object doesn't change unless you bind another list (what happens is just items are added or removed from the list), therefore the setter of the 'PersonList' property is not called & therefore "Notify property changed" doesn't trigger for 'PersonCount'.



          However as the 'PersonList' is a BindingList, added/removed items are reflected in the UI.



          Solutions



          1) Register 'PersonList' to ListChanged event and call 'Notify Property Changed' in the event handler.



              public BindingList<Person> PersonList
          {
          get { return personList; }
          set
          {
          if (personList != null)
          personList.ListChanged -= PersonList_ListChanged;

          personList = value;

          if (personList != null)
          personList.ListChanged += PersonList_ListChanged;

          OnPropertyChanged(nameof(PersonList));
          }
          }

          public PersonsDashboardViewModel()
          {
          PersonList = new BindingList<Person>();

          PersonList.Add(new Person("Name1", "Lname1"));
          PersonList.Add(new Person("Name2", "Lname2"));
          }

          private void PersonList_ListChanged(object sender, ListChangedEventArgs e)
          {
          OnPropertyChanged(nameof(PersonCount));
          }


          OR



          2) Call 'Notify Property Changed' for 'PersonCount' where you add person items.



              public void AddPersonItem()
          {
          PersonList.Add(new Person("Sean", "Brendon"));
          OnPropertyChanged(nameof(PersonCount));
          }





          share|improve this answer





















          • 2





            Your point 1) is dangerous! If you set PersonList one more time not in the constructor of PersonsDashboardViewModel the UI will not be updated. You have to more attentively read my answer

            – Rekshino
            Nov 23 '18 at 12:07











          • Your first solution did the work. I use a separate class with BusinessLogic to alter the viewmodel. The OnPropertyChanged method is private, too. Because of this I can`t use the OnPropertyChanged-Method of the viewmodel in this BusinessLogic.

            – Andreas Susewind
            Nov 23 '18 at 12:11











          • Agreed with @Rekshino , you have to be careful when registering events. Registering for the 'ListChanged' event in the setter of 'PersonList' is straightforward.

            – Praboda
            Nov 23 '18 at 13:25











          • Now it looks out better.

            – Rekshino
            Nov 26 '18 at 7:34














          1












          1








          1







          The problem in your code is, once you bind the 'PersonList' to the view model, the list object doesn't change unless you bind another list (what happens is just items are added or removed from the list), therefore the setter of the 'PersonList' property is not called & therefore "Notify property changed" doesn't trigger for 'PersonCount'.



          However as the 'PersonList' is a BindingList, added/removed items are reflected in the UI.



          Solutions



          1) Register 'PersonList' to ListChanged event and call 'Notify Property Changed' in the event handler.



              public BindingList<Person> PersonList
          {
          get { return personList; }
          set
          {
          if (personList != null)
          personList.ListChanged -= PersonList_ListChanged;

          personList = value;

          if (personList != null)
          personList.ListChanged += PersonList_ListChanged;

          OnPropertyChanged(nameof(PersonList));
          }
          }

          public PersonsDashboardViewModel()
          {
          PersonList = new BindingList<Person>();

          PersonList.Add(new Person("Name1", "Lname1"));
          PersonList.Add(new Person("Name2", "Lname2"));
          }

          private void PersonList_ListChanged(object sender, ListChangedEventArgs e)
          {
          OnPropertyChanged(nameof(PersonCount));
          }


          OR



          2) Call 'Notify Property Changed' for 'PersonCount' where you add person items.



              public void AddPersonItem()
          {
          PersonList.Add(new Person("Sean", "Brendon"));
          OnPropertyChanged(nameof(PersonCount));
          }





          share|improve this answer















          The problem in your code is, once you bind the 'PersonList' to the view model, the list object doesn't change unless you bind another list (what happens is just items are added or removed from the list), therefore the setter of the 'PersonList' property is not called & therefore "Notify property changed" doesn't trigger for 'PersonCount'.



          However as the 'PersonList' is a BindingList, added/removed items are reflected in the UI.



          Solutions



          1) Register 'PersonList' to ListChanged event and call 'Notify Property Changed' in the event handler.



              public BindingList<Person> PersonList
          {
          get { return personList; }
          set
          {
          if (personList != null)
          personList.ListChanged -= PersonList_ListChanged;

          personList = value;

          if (personList != null)
          personList.ListChanged += PersonList_ListChanged;

          OnPropertyChanged(nameof(PersonList));
          }
          }

          public PersonsDashboardViewModel()
          {
          PersonList = new BindingList<Person>();

          PersonList.Add(new Person("Name1", "Lname1"));
          PersonList.Add(new Person("Name2", "Lname2"));
          }

          private void PersonList_ListChanged(object sender, ListChangedEventArgs e)
          {
          OnPropertyChanged(nameof(PersonCount));
          }


          OR



          2) Call 'Notify Property Changed' for 'PersonCount' where you add person items.



              public void AddPersonItem()
          {
          PersonList.Add(new Person("Sean", "Brendon"));
          OnPropertyChanged(nameof(PersonCount));
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '18 at 13:24

























          answered Nov 23 '18 at 11:44









          PrabodaPraboda

          655




          655








          • 2





            Your point 1) is dangerous! If you set PersonList one more time not in the constructor of PersonsDashboardViewModel the UI will not be updated. You have to more attentively read my answer

            – Rekshino
            Nov 23 '18 at 12:07











          • Your first solution did the work. I use a separate class with BusinessLogic to alter the viewmodel. The OnPropertyChanged method is private, too. Because of this I can`t use the OnPropertyChanged-Method of the viewmodel in this BusinessLogic.

            – Andreas Susewind
            Nov 23 '18 at 12:11











          • Agreed with @Rekshino , you have to be careful when registering events. Registering for the 'ListChanged' event in the setter of 'PersonList' is straightforward.

            – Praboda
            Nov 23 '18 at 13:25











          • Now it looks out better.

            – Rekshino
            Nov 26 '18 at 7:34














          • 2





            Your point 1) is dangerous! If you set PersonList one more time not in the constructor of PersonsDashboardViewModel the UI will not be updated. You have to more attentively read my answer

            – Rekshino
            Nov 23 '18 at 12:07











          • Your first solution did the work. I use a separate class with BusinessLogic to alter the viewmodel. The OnPropertyChanged method is private, too. Because of this I can`t use the OnPropertyChanged-Method of the viewmodel in this BusinessLogic.

            – Andreas Susewind
            Nov 23 '18 at 12:11











          • Agreed with @Rekshino , you have to be careful when registering events. Registering for the 'ListChanged' event in the setter of 'PersonList' is straightforward.

            – Praboda
            Nov 23 '18 at 13:25











          • Now it looks out better.

            – Rekshino
            Nov 26 '18 at 7:34








          2




          2





          Your point 1) is dangerous! If you set PersonList one more time not in the constructor of PersonsDashboardViewModel the UI will not be updated. You have to more attentively read my answer

          – Rekshino
          Nov 23 '18 at 12:07





          Your point 1) is dangerous! If you set PersonList one more time not in the constructor of PersonsDashboardViewModel the UI will not be updated. You have to more attentively read my answer

          – Rekshino
          Nov 23 '18 at 12:07













          Your first solution did the work. I use a separate class with BusinessLogic to alter the viewmodel. The OnPropertyChanged method is private, too. Because of this I can`t use the OnPropertyChanged-Method of the viewmodel in this BusinessLogic.

          – Andreas Susewind
          Nov 23 '18 at 12:11





          Your first solution did the work. I use a separate class with BusinessLogic to alter the viewmodel. The OnPropertyChanged method is private, too. Because of this I can`t use the OnPropertyChanged-Method of the viewmodel in this BusinessLogic.

          – Andreas Susewind
          Nov 23 '18 at 12:11













          Agreed with @Rekshino , you have to be careful when registering events. Registering for the 'ListChanged' event in the setter of 'PersonList' is straightforward.

          – Praboda
          Nov 23 '18 at 13:25





          Agreed with @Rekshino , you have to be careful when registering events. Registering for the 'ListChanged' event in the setter of 'PersonList' is straightforward.

          – Praboda
          Nov 23 '18 at 13:25













          Now it looks out better.

          – Rekshino
          Nov 26 '18 at 7:34





          Now it looks out better.

          – Rekshino
          Nov 26 '18 at 7:34













          2














          You have to invoke OnPropertyChanged(nameof(PersonCount)); where you modify the list. If it's not possible, then you have to subscribe to CollectionChanged for PersonList in setter and invoke OnPropertyChanged(nameof(PersonCount)); in event handler.






          share|improve this answer
























          • Thank you for your answer. My Personlist is instantiated in the constructor respectively in a reset-method to reset the viewmodel if needed. Is it what you mean with "in setter" ? Thanks in advance.

            – Andreas Susewind
            Nov 23 '18 at 14:44






          • 1





            @AndreasSusewind If you reassign the list in the reset method, then you have to unsubscribe the previous event handler and set the new one. Praboda has changed the answer, now is subscription in setter.

            – Rekshino
            Nov 26 '18 at 7:27
















          2














          You have to invoke OnPropertyChanged(nameof(PersonCount)); where you modify the list. If it's not possible, then you have to subscribe to CollectionChanged for PersonList in setter and invoke OnPropertyChanged(nameof(PersonCount)); in event handler.






          share|improve this answer
























          • Thank you for your answer. My Personlist is instantiated in the constructor respectively in a reset-method to reset the viewmodel if needed. Is it what you mean with "in setter" ? Thanks in advance.

            – Andreas Susewind
            Nov 23 '18 at 14:44






          • 1





            @AndreasSusewind If you reassign the list in the reset method, then you have to unsubscribe the previous event handler and set the new one. Praboda has changed the answer, now is subscription in setter.

            – Rekshino
            Nov 26 '18 at 7:27














          2












          2








          2







          You have to invoke OnPropertyChanged(nameof(PersonCount)); where you modify the list. If it's not possible, then you have to subscribe to CollectionChanged for PersonList in setter and invoke OnPropertyChanged(nameof(PersonCount)); in event handler.






          share|improve this answer













          You have to invoke OnPropertyChanged(nameof(PersonCount)); where you modify the list. If it's not possible, then you have to subscribe to CollectionChanged for PersonList in setter and invoke OnPropertyChanged(nameof(PersonCount)); in event handler.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 10:58









          RekshinoRekshino

          2,7861728




          2,7861728













          • Thank you for your answer. My Personlist is instantiated in the constructor respectively in a reset-method to reset the viewmodel if needed. Is it what you mean with "in setter" ? Thanks in advance.

            – Andreas Susewind
            Nov 23 '18 at 14:44






          • 1





            @AndreasSusewind If you reassign the list in the reset method, then you have to unsubscribe the previous event handler and set the new one. Praboda has changed the answer, now is subscription in setter.

            – Rekshino
            Nov 26 '18 at 7:27



















          • Thank you for your answer. My Personlist is instantiated in the constructor respectively in a reset-method to reset the viewmodel if needed. Is it what you mean with "in setter" ? Thanks in advance.

            – Andreas Susewind
            Nov 23 '18 at 14:44






          • 1





            @AndreasSusewind If you reassign the list in the reset method, then you have to unsubscribe the previous event handler and set the new one. Praboda has changed the answer, now is subscription in setter.

            – Rekshino
            Nov 26 '18 at 7:27

















          Thank you for your answer. My Personlist is instantiated in the constructor respectively in a reset-method to reset the viewmodel if needed. Is it what you mean with "in setter" ? Thanks in advance.

          – Andreas Susewind
          Nov 23 '18 at 14:44





          Thank you for your answer. My Personlist is instantiated in the constructor respectively in a reset-method to reset the viewmodel if needed. Is it what you mean with "in setter" ? Thanks in advance.

          – Andreas Susewind
          Nov 23 '18 at 14:44




          1




          1





          @AndreasSusewind If you reassign the list in the reset method, then you have to unsubscribe the previous event handler and set the new one. Praboda has changed the answer, now is subscription in setter.

          – Rekshino
          Nov 26 '18 at 7:27





          @AndreasSusewind If you reassign the list in the reset method, then you have to unsubscribe the previous event handler and set the new one. Praboda has changed the answer, now is subscription in setter.

          – Rekshino
          Nov 26 '18 at 7:27


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445315%2fwpf-adding-an-item-to-a-bindinglist-not-update-another-property-in-viewmodel%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Berounka

          Fiat S.p.A.

          Type 'String' is not a subtype of type 'int' of 'index'