So far I have been implementing MVVM in my silverlight app pretty well, I just had one question. I have a few User Controls that I made and was wondering if they should be placed in the Views folder or in a seperate folder call UserControls. Is a user control considered a view?

  • I would consider them views since they have a presentation component, but I would still organize them in a "UserControls" folder. – Bernard Jan 27 '12 at 16:38

A View can be a UserControl or a DataTemplate. A UserControl could be a View, however it is always a custom Control. There really is no relationship between the two.

So I would put the UserControls that are Views in your Views folder, while UserControls that are customized controls in your UserControl folders.

And personally, I wouldn't sort an MVVM application into Model, View, and ViewModel folders. It makes maintenance too obnoxious. Suppose you wanted to add a field to an item. You have to hunt down that item in all 3 folders to make the change. In larger applications, this is very annoying.

Instead I'd suggest grouping your objects based on their functionality. For example, I would place my CustomerView, CustomerViewModel, and CustomerModel all in a single folder called Customer.

In larger applications, I will separate the MVVM layers out into separate libraries, however the same concept still applies. The project that holds my data will store all Customer Models in a folder called Customer, my project holding my business logic will store all the Customer ViewModels in a folder called Customer, and my UI layer will store all Customer-related Views (UserControls and/or ResourceDictionaries w/ DataTemplates) in a single folder called Customer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.