Note that there are some explanatory texts on larger screens.

plurals
  1. POGet notified when properties change in the Model
    primarykey
    data
    text
    <p>There seems to be conflicting thoughts on whether <code>INotifyPropertyChanged</code> should be implemented in the Model or not. I think that it should be implemented in the ViewModel, but I can't figure out how it would be accomplished. There are plenty of mentions of this same idea all over stackoverlow.com ( <a href="https://stackoverflow.com/questions/6922130/in-mvvm-model-should-the-model-implement-inotifypropertychanged-interface">In MVVM model should the model implement INotifyPropertyChanged interface?</a>, <a href="https://stackoverflow.com/questions/772214/in-mvvm-should-the-viewmodel-or-model-implement-inotifypropertychanged">In MVVM should the ViewModel or Model implement INotifyPropertyChanged?</a>), but I can't find any example to show how to do it.</p> <p>Let's say for example I have a model Person:</p> <pre><code>Public Person { public int Age { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public void NameChange( string newName ); } </code></pre> <p>How would I implement the ViewModel so that changes in <code>Age</code>, <code>FirstName</code>, or <code>LastName</code> are all recognized?</p> <pre><code>Public PersonViewModel : INotifyPropertyChanged { Person _person; public event PropertyChangedEventHandler PropertyChanged; void OnPropertyChanged(string propertyName) { if(this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } //ctor, Properties, etc... } </code></pre> <p><strong><em>EDIT - Clarification:</em></strong></p> <p>So <strong>without changing the Person model</strong> how do I modify the ViewModel to get notified of the updates? </p> <p>Is that even possible? If not, how are those that subscribe to the "INPC in the model is <em>baaaad</em>" get notified of changes in the model?</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.
 

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