MVVM model to view

As far as I understand, ViewModel interacts with View through data binding. But how can you create UIElements for View in ViewModel.

Thank.

+3
source share
3 answers

The ViewModel should not create UIElements directly, because the ViewModel should not be dependent on the view. The ViewModel provides data that a view can interact with (i.e., UIElements).

, View, : View-first ViewModel. , ViewModel. ViewModel ( ). .

UIElements, DataBinding DataTemplates ControlTemplates.

+6

MVVM , , , , unit test.

, , ViewModel , View ViewModel , View ViewModel ViewModel.

+2

, .

Container , modelView UIElements UIElement . , . . .

MVVM . . .. ListBox MemberPath ItemTemplate ButtonBase Commanding! ListBox Commanding.

My suggestion is instead of creating a dynamic object. Use DataTemplates and change related items in ModelView, then the view will be automatically created for you. For a complex senario, this can be difficult. We do all this in order to maintain the MVVM structure.

0
source

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


All Articles