Note that there are some explanatory texts on larger screens.

plurals
  1. POMVVM refresh model
    primarykey
    data
    text
    <p>I have a project in WPF with the MVVM-Pattern.</p> <p>The view has a listview of Persons(FirstName, LastName, Town) and next to the list are the details of the person(FirstName,LastName,ZIP) with a button(Save). If you click to a person on the left side, the person details on the right side will load automatically.</p> <p>In the ViewModel I have an ObservableCollection of Person-Models. (Person list)</p> <p>The Person Model includes some propertys like FirstName, LastName, Town, Zip. (Details).</p> <p>When I change the ZIP, the Town will updated automatically(in the setter switch-case) e.g. ZIP '11111' Town 'Town1' / ZIP '22222' Town 'Town2'.</p> <p>The Person Model includes also an ICommand "SavePerson" to Save Changes.</p> <p>Now when i click to an item in the listview the details will load automatically. When I change the FirstName or LastName and click "Save" the listview will change the First and the LastName of the selected item, that's ok. Now when I change the ZIP from '12345' into '11111' the town in the listview is still the old one and not 'Town1'.</p> <p>Have you an idea to fix this problem, without to implement the INotifyPropertyChanged-Interface in the Model?</p> <p>Some code: Model: </p> <pre><code>public class Person { private string _firstName = string.Empty; private string _lastName = string.Empty; private string _zip = string.Empty; private string _town = string.Empty; public string FirstName { get { return _firstName; } set { _firstName = value; } } public string LastName { get { return _lastName; } set { _lastName= value; } } public string ZIP { get { return _zip; } set { switch (value) { case "11111": this.Town = "Town1"; break; case "22222": this.Ort = "Town2"; break; default: break; } _zip = value; } } public string Town { get { return _town; } set { _town= value; } } public ICommand SaveNameCommand { get { return new DelegateCommand((param) =&gt; this.SaveName(param)); } } private void SaveName(object parameter) { string[] param = ((string)parameter).Split(new char[] { ':' }); FirstName = param[0]; LastName = param[1]; PLZ = param[2]; } } </code></pre> <p>ViewModel:</p> <pre><code>public class PersonList { private readonly ObservableCollection&lt;Person&gt; _persons = new ObservableCollection&lt;Person&gt;(); private Person _currentSelectedPerson = new Person(); public PersonList() { this._persons.Add(new Person() { FirstName = "First1", LastName = "Last1", Ort = "Ort1", PLZ = "112" }); this._persons.Add(new Person() { FirstName = "First2", LastName = "Last2", Ort = "Ort2", PLZ = "122" }); this._persons.Add(new Person() { FirstName = "First3", LastName = "Last3", Ort = "Ort3", PLZ = "1132" }); } public IEnumerable&lt;Person&gt; Persons { get { return this._persons; } } } </code></pre>
    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