Design decision: MVVM and WPF with two views?

advertisements

I hope I didn't oversee an old question that's has stated the same, but as far as I can see they were all more specialized.

I wanted to know, if I am "on the right track". In the past I did some WinForms stuff with C# (mainly .net-3.5) and now I want to use / learn WPF for a little side-project. At the moment I am reading much about MVVM and other implementing-details when using WPF (.net4).

What I need to achieve is:

I want to have a kind of searchtool for an oracle-database. The Database-connection and so on is fixed, up and running. So no work to do on this part. The new tool should be ran on a windows7-desktop-pc and a windows7-tablet-pc. So I want/need two different Views one usual mouse-keyboard-interaction-gui and one optimized for touch-input.

So I had the idea of using one Model, one View-Model and two Views. I wouldn't want to use IOC via Unity or something of this kind as this would add a layer of complexity that would be overkill for this little side-project.

My actual Question:

Is this the right approach (using 2 Views with one View-Model) or am I completely wrong here (maybe DataTemplates would be better here?)? And what are good approaches to have this implemented?

Thanks in advance!


The idea behind having a ViewModel would be to have a place to consolidate view-related logic in a place that has no direct dependencies to view-specific stuff. So, yes, I'd say your approach is fine.

DataTemplates seem more suited for "smaller" View Models, so while a DataTemplateSelector could nicely do the job of selecting a Template based on your circumstances I think it's worth investing some extra code that can do that for you for full-sized Controls.

You will have to figure out whether you can automatically detect the way your users are using the app and maybe have your view names follow a convention such that choice of view can happen more or less automatically.