StandardViewModel vs. ViewModel

Jul 11, 2013 at 7:17 PM
Just a sanity check.

I should use the StandardViewModel when I will have lists of data to be rendered in a listbox and the ViewModel when I have other types of data.

Some styles/templates require the StandardViewModel as they will use those properties to do certain things. It might be nice to have a list of the various layout views and which ones work best with a ViewModel and StandardViewModel.

For my sanity, I have 2 files that contain an extract some of your code to reference files.

The first is an extract of the case statements that show all the standardView options - so it looks sort of like this:
case "Block": return new ListBoxSmartDataTemplate { DefaultColumns = "Logo1, Text1, Text2, Number1" };
case "Image": return new ListBoxSmartDataTemplate { DefaultColumns = "Logo1, Image1, Number1" };
case "LargeImage": return new ListBoxSmartDataTemplate { DefaultColumns = "Logo1, Image1, Number1" };
.....
From there, I can quickly pick the desired style/theme.

I also have one that lists all the icons you provide. It might be helpful to have some of these posted for easy reference (since, once we understand they are as easy to read as more complete docs). Or do you have these somewhere and I missed them?

Also, I assume that you use ListBoxSmartDataTemplate() for all but the metro themes because the metro theme takes advantage of some other values to do the layout (or the others are the exception and need additional code to look differently.)

Thanks!

Fletcher
Coordinator
Jul 12, 2013 at 12:31 AM
Well, that is a good question.

The StandardViewModel is certainly extremely useful for all kinds of lists, especially the read-only ones. Sometimes there even are other scenarios (even edit forms) that can benefit from having some of those standard things there. But as a simple rule, you can use the standard view model class for lists, and all the standard templates we have rely on the standard view models. So whenever you use any of the standard templates, you need to use a standard view model.

Now, to take this discussion a step further: The question in many cases has become "what is the downside of using the standard view model?". Well, the main downside would be that you are wasting memory if you use a standard view model, but you don't actually use any of its properties. And that's about it. So in some ways, I have pondered whether we shouldn't make the standard view model as the default. In some ways, if feels "wrong" and "dirty" to me, but realistically speaking, it probably doesn't matter to have a little bit of added overhead. Nobody is ever going to notice on a modern machine. I have to think about all of this more.

This sort of stuff is really going to matter with some of the new things we are currently cooking up. I have given some very serious thought around defining view models more efficiently, because lets face it: Defining view models is a PITA! It is wordy for what they do. There should be better ways. In fact, I have now been thinking about that for years and we are about to make something around that available. And in that, it will be interesting to pick a default for a view model class. But anyway: I am getting ahead of myself. :-)


Markus