Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends really, if your model already implements INotifyPropertyChanged and/or IError info you might want to bind right to the model property. However if you want to do special validation and other stuff that the model knows nothing about you add the property wrappers in your view model.</p> <p>This article gives a good example of a hybrid: <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/dd419663.aspx</a></p> <p>Often my MV properties look like this and thats quite normal:</p> <pre><code> public string Symbol { get { return Model.Symbol; } set { Model.Symbol = value; this.NotifyOfPropertyChange(() =&gt; this.Symbol); } } </code></pre> <p>I often do NOT implement INotifyPropertyChanged in the model and thus often I have to write the wrappers.</p> <p>EDIT: In response to your additional information: It can be a bit tricky to to keep the collections and lists in sync. In your case what I would do is to create a view model for each model class, but NOT wrap all the properties just access them like this: {Bindng Customer.Name}. But of course you have to create a wrapper for the collections which contain view models. The Prism documentation is, as they say themselves, just guidance, if your scenario needs a different approach then this is fine.</p> <p>Take a look at this code. I only wrap the collections and the properties I will access through the model. This gives you the best of both worlds. Then IF you need a special property that does not belong into you model you can add it to the view model (see the CustomerViewModel), or if you need special notification for a certain properties.</p> <pre><code>class CompanyViewModel{ public CopanyViewModel(Company c){ foreach(var customer in c.Customers) Customers.Add(new CustomerViewModel(customer); } public Company Company {get;set;} public ObservableCollection&lt;CustomerViewModel&gt; Customers {get;set;} } class CustomerViewModel{ public CustomerViewModel(Customer c){ Customer = c; } public Customer Customer {get;set;} public Brush CustomerBackground{ get{ if(Customer.Active) return Brush.Greeen; else return Brush.Red; } } } </code></pre> <p>(This code might not work, I just typed it in here.)</p> <p>Now, if you need changed notification for all models and all properties you have to either implement it in you model or in wrap all properties in a view 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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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