Forgive me, but I've only really used WinForms in the past, and MVVM and WPF are new to me.

For those who use MVVM with WPF, do you actually make separate directories (namespaces) for your Models, Views and ViewModels files or is it more of an abstract idea?

I fundamentally understand what the MVVM process does, I just don't completely understand how it is truely implemented. For example:

If we store our data in a SQL server, in a general respect, wouldn't that dataset be the Model? It certainly represents the data and how it is all related. A "model" so to speak of the data.
If a dataset is a Model, the ViewModel is where I lose all understanding. If the ViewModel interacts with the Model on behalf of the view, and (I imagine) does most of the business logic, how can that not be in the same class as the view? I mean, if I have a textbox that a user is supposed to enter an integer in, but instead types a string, how am I supposed to validate the input before it is sent to the Model unless I check the data when the user enters it (which is in the View, right?). I can't do this because if I use databinding (which is what WPF seems to be popular for), I don't get the oportunity to inspect the data entered. Would the ViewModel just be a class with event handlers to validate data and manipulate it?

The lack of codebehind makes me very nervous. I know I need to just get used to it, but I'm not a fan of things being done "automagicly" so to speak, and really would like to be able to validate things as the user is interacting with the interface. That way if the user types a string instead of an integer and they leave the textbox, I want the ability to tell the user immediately, either by preventing it alltogether by intercepting keypresses, or by changing the color of the textbox border. Maybe even get really annoying and show a messagebox.

I don't see how this can be done with MVVM, unless there is a LOT of extra code to be written in the ViewModels and instead of binding to a datasource, I bind to the ViewModel and the ViewModel sends the changes on to the Model...

Am I thinking about this in the wrong way or did I miss something when reading the documentation?

I guess CodeProject has some good articles about your subject. Article1. Article2.
You can write a complete WPF application without using XAML. It is just going to be a little harder I think. With WPF you could have two teams. One does the design and producing XAML and the other team does the coding.
Hope this explanation and the articles help a little bit.

ddanbe,

I was only using validating user input as an example, but was more interested in the overall process of MVVM and how it is actually implemented.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.