Note that there are some explanatory texts on larger screens.

plurals
  1. POFor MVVM, what is the best practice for viewmodel to export the property in model to view?
    text
    copied!<p>As a new one to WPF, I start my MVVM travel recently. I can understand the orginal intension about why we need MVVM, but some of the implementation detail still confuse me a lot.</p> <p>Here is one of my questions: </p> <p><strong>How should I export the property in <code>model</code> to <code>View</code> via <code>ViewModel</code></strong></p> <p>I can show some of my idea here, so please share your view with me.</p> <p>Here is one of my implementation:</p> <pre class="lang-cs prettyprint-override"><code> class MyModel : INotifyPropertyChanged { private String _name; public String Name { get { return _name; } set { if (_name != value) { _name = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Name")); } } } } public event PropertyChangedEventHandler PropertyChanged; } class MyViewModel { private MyModel _model; public MyModel Model { get { return _model; } set { _model = value; } } } </code></pre> <p>I think the problem for this is we do not decouple the view from model. And the view need to know every detail about the model implementation to accomplish the Binding process. And exporting the propert in <code>Model</code> <strong>directly</strong> to view from <code>ViewModel</code> cannot be treat as a good design in my opinion.</p> <p>So I hope you can share your experience on the design about this topic.</p> <p>BTW, If we export many object, such as, a <code>List</code> of <code>MyModel</code> object to view from viewmodel, how can I implement this to decouple the view from model?</p>
 

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