WPF MVVM:查看模型中的信息
假设我在 WPF MVVM 应用程序中有可拖动节点。我需要加载并保存节点的位置及其逻辑。最简单的方法是通过存储库将位置连同逻辑一起保存在一个 xml 文件中。但是,这意味着我在模型和视图模型中拥有视图信息。
对于这种情况是否有最佳实践方法,也许我到目前为止还没有考虑过?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的应用程序关心它向用户显示的 UI 元素的位置,那么我会说定义此位置的数据是模型中非常合法的部分。
不要将 UI 与模型和 ViewModel 解耦的理想与实际业务需求混淆。例如,在像 Visio 这样的应用程序中,您可以说页面中对象的确切位置是“仅供查看的详细信息”,重要的只是对象的属性以及它们之间的连接。然而,从用户的角度来看,对象在工作区中的放置非常重要。换句话说,它是数据模型的一部分。
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.