WPF MVVM: View Information in a Model

Suppose I have draggable nodes in a MVVM WPF application. I need to load and save the position of the node, as well as its logic. The easiest approach is to save the position along with the logic in one XML file through the repository. However, this would mean that I have view information in the model and view model.

Is there a better approach to this scenario, perhaps one that I have not considered so far?

+4
source share
1 answer

If your application cares about positioning the user interface elements that it displays to the user, I would say that the data defining this positioning is a very legitimate part of your models.

Do not confuse the ideal of decoupling the interface from models and ViewModels with real business requirements. For example, in an application such as Visio, you can say that the exact placement of objects on a page is β€œview-only”, and most importantly, it is only the properties of the object and the relationship between them. However, from the point of view of the user, it is very important to place objects in the workspace. In other words, this is part of your data model.

+7
source

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


All Articles