4
votes

Let's assume I have dragable nodes in an WPF MVVM application. I need to load and save the position of a node as well as its logic. The simplest approach would be to save the position along with the logic in one xml file through a repository. However, that would mean I have view information in the model and view model.

Is there a best practice approach regarding this scenario, maybe one that I have not considered so far?

1
Why are the nodes dragable? Which of the "position" information do you want to store? Would it be enough to store the hierarchical information (level, siblings) in the model and from that create the graphical information in the view?Martin Hennings
Nodes and their connections represent a graphical data manipulation procedure. The user must be able to visualise the process as siutable (similar to Visio). I have to save the x/y position in the canvas as I do not create the positions and nodes and the hierarchy is flexible.ps23

1 Answers

7
votes

If your application cares about the positioning of the UI elements it displays to the user, then I 'd say that the data defining this positioning is a very legitimate part of your Models.

Don't confuse the ideal of decoupling the UI from your Models and ViewModels with real business requirements. For example, in an application like Visio you could say that the exact placement of objects in the page is a "view-only detail", and what matters is only the properties of the object and the connections between them. However, from the user's perspective, the placement of objects in the workspace very much matters. In other words, it is part of your data model.