WPF MVVM: View information in the model
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 reposito开发者_高级运维ry. 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?
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.
精彩评论