MVVM - DataGrid grouping, what part of the pattern is responsible for this RRS feed

  • Question

  • 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, 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 ModelView with View specific logic.

    Any ligt that can be shed on this?

    Friday, June 11, 2010 7:21 AM


  • Hi Rsstuij,

    I think it would be better if you put the group in view. Firstly, the grouping ability is just a result of the data presentation, and it has nothing to do with the view model logic. and it is possible that we need a view without the grouping ability, in this situation we only need to create a new view, and the view model is not contaminated. In this way, we’ll also get loose coupling between view model and view.

    Just my two cents.

    Best regards,
    Linda Liu

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Linda Liu Friday, June 18, 2010 1:34 AM
    Tuesday, June 15, 2010 10:28 AM