Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF MVVM Single ViewModel for Display and Editing
    text
    copied!<p>I am using the example from <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="nofollow">Josh Smith</a>. He has a WorkspaceViewModel which display a list of CustomerViewModels. He is using the same ViewModel for displaying all Customers and for editing one single customer.</p> <p>Is this a good practice? If I have a list of CustomerViewModels I dont need the SaveCommand or the CloseCommand or some IsSelected Flag.</p> <p>Is it better to have a seperate EditCustomerViewModel? But how to deal with Workspace related stuff? For example:</p> <pre><code>public class Workspace : ViewModel { public ICommand CloseCommand; } public class AllCustomers : Workspace { public ObservableCollection&lt;CustomerViewModel&gt; CustomerViewModels; } // Option A (one ViewModel for display and edit): public class CustomerViewModel : ? { public string CustomerName; public ICommand SaveCommand; } </code></pre> <p>Or seperation:</p> <pre><code>// Option B: public class CustomerViewModel : ViewModel { public string CustomerName; } public class EditCustomerViewModel : Workspace { public CustomerViewModel CustomerViewModel; public ICommand SaveCommand; } // Option C (CustomerViewModel does not need CloseCommand but EditCustomerViewModel does): public class CustomerViewModel : Workspace { public string CustomerName; } public class EditCustomerViewModel : CustomerViewModel { public ICommand SaveCommand; } </code></pre> <p><strong>Edit:</strong> I try to clarify my problem. In the CustomerViewModel in the example of Josh Smith, he has Commands for closing and saving a customer. In the AllCustomerView he has a GridView that binds to a ObservableCollection of CustomerViewModels. But in the GridView the both commands are not necessary. In the GridView I can ignore both commands, but is that a good design? </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