ViewModel / View relationships and check

In our WPF application, we want to use the basic MVVM pattern. We discussed this, and there were some uncertainties regarding the ViewModel / View relationship and validation. Could you say that this is a good understanding?

  • Each view has one and only one ViewModel and the purpose of the ViewModel is to ensure that it is presented with data and process all its viewing events and commands. (Are there instances in which one ViewModel serves two views, such as the standard XAML input form and CSV Import form submission, which provides the same data as the form, and therefore should have the same validation?)

  • Validation is only performed using the ViewModel when, for example, the view throws a ChangedFocus or SaveButtonPressed event, etc.

  • The model is pretty dumb , just being a data structure based on one or more tables from the database, but the model itself can’t cope, for example, confirmation. Even the ViewModel creates and holds ObservableCollection objects, for example. "Clients", not the model itself.

Any feedback is appreciated.

+5
source share
3 answers

Each view has one and only one ViewModel

, , ViewModel. , , View ViewModels. , , .

, ViewModel

, .

ViewModel

. , IDataErrorInfo . , , , . - , .

, . - , .

+5

. : . , , . ContentPresenter, ( ) DataTemplate .

+3

, ViewModel

.

The model can be as smart as you like. And this may include a β€œcheck” to ensure integrity, but this check will not include messages that appear in the user interface.

+1
source

All Articles