Note that there are some explanatory texts on larger screens.

plurals
  1. POAgain, ObservableCollection doesnt Update item
    primarykey
    data
    text
    <p>Thats my first project using MVVM , MVVM light. I have a listbox, that gets refreshed from the PersonList Observable collection, adding and removing refresh it normal. the problem is when editing an item.</p> <p>I looked for all the solutions for this problem, nothing worked, which make me think that I missed something. </p> <p>so here is the code : </p> <pre><code> public class AdminViewModel : ApplicationPartBaseViewModel { private ObservableCollection&lt;Person&gt; personList; public AdminViewModel() { this.context = new Entities(); this.SavePersonCommand = new RelayCommand(() =&gt; this.SavePerson ()); this.PersonList = new ObservableCollection&lt;Peson&gt;(context.Person.OrderBy(o =&gt; o.PersonName).ToList()); } public ObservableCollection&lt;Person&gt; PersonList { get { return personList; } set { this.personList = value; RaisePropertyChanged("PersonList"); } } private void SavePerson() { //Add and update code here this.context.SaveChanges(); RaisePropertyChanged("PersonList"); } } </code></pre> <p>Person Class is Autogenerated template from the DataModel edmx</p> <pre><code> //------------------------------------------------------------------------------ // &lt;auto-generated&gt; // This code was generated from a template. // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // &lt;/auto-generated&gt; //------------------------------------------------------------------------------ public partial class Person { #region Primitive Properties public virtual int PersonId { get; set; } public virtual string PersonName { get; set; } public virtual Nullable&lt;int&gt; PersonAge { get; set; } #endregion #region Navigation Properties public virtual ICollection&lt;Humans&gt; Humans { get { if (_human == null) { var newCollection = new FixupCollection&lt;Human&gt;(); newCollection.CollectionChanged += FixupHuman; _human = newCollection; } return _human; } set { if (!ReferenceEquals(_human, value)) { var previousValue = _human as FixupCollection&lt;Human&gt;; if (previousValue != null) { previousValue.CollectionChanged -= FixupHuman; } _human = value; var newValue = value as FixupCollection&lt;Human&gt;; if (newValue != null) { newValue.CollectionChanged += FixupAssets; } } } } private ICollection&lt;Human&gt; _human; #endregion #region Association Fixup private void FixupHuman(object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { foreach (Human item in e.NewItems) { if (!item.Person.Contains(this)) { item.Person.Add(this); } } } if (e.OldItems != null) { foreach (Human item in e.OldItems) { if (item.Person.Contains(this)) { item.Person.Remove(this); } } } } #endregion } </code></pre> <p>I thought that MVVM light update the item when I call RaisePropertyChanged. I am so confused. </p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload