I am using the example from Josh Smith. 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.
Is this a good practice? If I have a list of CustomerViewModels I dont need the SaveCommand or the CloseCommand or some IsSelected Flag.
Is it better to have a seperate EditCustomerViewModel? But how to deal with Workspace related stuff? For example:
public class Workspace : ViewModel
{
public ICommand CloseCommand;
}
public class AllCustomers : Workspace
{
public ObservableCollection<CustomerViewModel> CustomerViewModels;
}
// Option A (one ViewModel for display and edit):
public class CustomerViewModel : ?
{
public string CustomerName;
public ICommand SaveCommand;
}
Or seperation:
// 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;
}
Edit: 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?