Regarding ViewModel

I am trying to understand the ViewModel part of the MVVM template . My current approach is to have a class without any logic (important), except that it implements INotifyPropertyChanged . A class is just a set of properties, a structure, if you want, describing as little data as possible. I am considering this model Model .

Most of the WPF code that I am writing is the configuration dialogs that configure the specified model. Dialog encoding provides a property that returns an instance of the model. In the XAML code, I bind to the sub-properties of this property, thereby binding directly to the model properties. Which works well, since it implements INotifyPropertyChanged. I am considering this View settings dialog .

However, I really could not understand what this ViewModel is all about. The articles I read suggest that the ViewModel should combine View and Model together, providing the logic that the Model lacks, but it's still difficult to go directly to the view. It's right? Would, in my example, the reverse code of the settings dialog be considered ViewModel ?

I just feel a little lost and would like my peers to debunk some of my assumptions. Am I completely disconnected here?

+3
source share
4 answers

Since your model fits perfectly into your view, i.e. your dialog (settings dialog) can directly communicate with the data structures of the model, you are lucky that you do not need a presentation model.

However, there are many other cases where this is not the case: imagine that you have a view that is a direct display of a database table, but you want the user interface to not exactly match this abstraction.

" ", , setting_name, setting_value. , , , ; , , " ", " " .. , UserName, MailAddress .

+2

, , ViewModel. ViewModel - , . API, (, WPF SilverLight).

, ViewModel ICommand , . , , .

View , , ViewModel.

, , , View . - , - -, INotifyPropertyChanged, ICommand .

- MVVM. ViewModel .

+1

ViewModel , . , , . , , , / ViewModel, , .

MVVM - , unit test , , ? , , .

0

- . ViewModel - . - Window Page DataTemplate, , XAML.

. . , . , - , .

. . , , . ( , . , , Command, IEditableObject.)

There is no connection between the view and the model. Usually you can make significant changes to the model, which, if they have no consequences for the user interface, also do not require changes in the presentation. Usually, you can make significant changes to the functionality of the user interface without affecting the data model (if these changes do not require new functionality in the data model).

0
source

Source: https://habr.com/ru/post/1748106/


All Articles