I’ve been tinkering around with the MVVM pattern and now I’m trying to implement a little application based on it.
This application has a datagrid in which, surprisingly enough, some data is presented. Now I’m trying to add some grouping ability to it. I know how to write this in code (C# and XAML), but I’m wondering in what layer I should put the responsible code.
One part of me tells me it should be in the view, because it’s code especially for that specific view. It’s not generic and serves one purpos: to group the data.
On the other hand I think I should handle it in the ViewModel using a command. It feels, though, as if I’m contaminating my ViewModel with View specific logic.
Any ligt that can be shed on this?
In most of my MVVM apps I try to divide responsibilities like this:
translation of viewmodel data to
pixels. Usually this results in mostly XAML and very little code behind.
view-specific logic like grouping
etc. I often even have multiple viewmodels per view. You can have a main viewmodel that exposes a list of sub-viewmodels per group to your view for example to implement grouping.
more than one viewmodel it’s probably
domain logic and should go into the
domain model.
So I think grouping should go in the viewmodel.