WPF DataGrid保存更改 [英] Wpf datagrid save changes

查看:99
本文介绍了WPF DataGrid保存更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在wpf中保存对数据网格所做的更改.数据应保存在resx文件中,如果没有任何文件..而不是数据库中.

问候
pavankumar

How to save changes made to a datagrid in wpf.The data should be save in resx file ,if not any file ..but not to database.

regards
pavankumar

推荐答案

如何将数据网格与数据绑定?

这个想法是:您不应该将控件中的任何数据立即保存到文件中.这种设计很难维护.您需要拥有一个单独的数据层,无论它是什么,并将其绑定到UI控件,并从数据层而不是控件中保存数据.即使您没有使用数据绑定,这也意味着您通过手动"代码绑定了此控件,其设计应相同:您将数据层中的数据填充到视图中,视图的编辑应使数据无效并与之同步数据层,数据层中的更改应更新视图.这种方法最接近的建筑模式是MVC.

我建议您学习并分析以下建筑模式的适用性( http://en.wikipedia .org/wiki/Architectural_pattern_(computer_science) [^ ]):

MVVM —模型视图视图模型,
http://en.wikipedia.org/wiki/Model_View_ViewModel [> http://en.wikipedia.org/wiki/Model-view-controller [ ^ ])),

MVA —模型视图适配器,
http://en.wikipedia.org/wiki/Model–view–adapter [ ^ ],

MVP —模型视图呈现器,
> http://en.wikipedia.org/wiki/Model-view-presenter [ ^ ].
请注意这些架构的动机.如果您了解它,就可以提出更好的设计思路.

—SA
How you bind data grid with data?

The idea is: you should not save any data from controls immediately to file. This design is hard to maintain. You need to have a separate data layer, whatever it is and bind it to you UI controls and save your data from you data layer, not from control. Even of you don''t use data binding, it means you bind this control through "manual" code, the design should be the same: you populate data from data layer to view, editing of the view should invalidate data and synchronize it with data layer, changes in data layer should update the view. The closest architectural pattern for this approach is MVC.

I suggest you learn and analyze applicability of the following architectural patterns (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

—SA


这篇关于WPF DataGrid保存更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆