简体   繁体   English

在WPF应用中存储数据的最佳方法

[英]Best way to store data in wpf app

I just want to know about the best way to store simple data in wfp application. 我只想了解在wfp应用程序中存储简单数据的最佳方法。 I'm using SQL CE, but sometimes I need to store simple data (for instance one string). 我正在使用SQL CE,但有时我需要存储简单数据(例如一个字符串)。 I don't want to use for it db, and I think it's the right decision. 我不想为此使用db,我认为这是正确的决定。

Could you please give me a guidance on how should I do that in best way or any useful resource? 您能否给我一个指导,说明如何以最好的方式或任何有用的资源进行操作? Is there any particular features data settings storage for pattern MVVM? 模式MVVM是否有任何特定的功能数据设置存储?

Thank You. 谢谢。

Use Settings for exactly this scenario. 正是在这种情况下使用设置。 It's simple, allows per user and system wide scenarios and is build into Visual Studio nicely. 它很简单,允许在每个用户和系统范围内使用,并且很好地内置到Visual Studio中。

Double clicking on Settings.settings in the Properties folder of your project (in Solution Explorer) brings up the editor and you can access these in code with something simple like Properties.Settings.Default.StringPropertyX . 双击项目(在解决方案资源管理器中)的Properties文件夹中的Settings.settings,将打开编辑器,您可以使用诸如Properties.Settings.Default.StringPropertyX简单代码通过代码访问它们。

http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx http://msdn.microsoft.com/zh-CN/library/aa730869(v=vs.80).aspx

if you're going to be upgrading in the future, I suggest that you create a small abstraction layer that you can upgrade to using any DB or other source, when you need to. 如果将来要升级,建议您创建一个小的抽象层,可以在需要时使用任何数据库或其他源进行升级。 Until you do the upgrade, I would suggest a simple XML file using XDocument and XElement (and the rest of that api). 在进行升级之前,我建议使用XDocument和XElement(以及该api的其余部分)创建一个简单的XML文件。 The reason why I am suggesting this is because you can use Linq on them easily and this enables you to change the provider in the future without any problems. 我建议这样做的原因是因为您可以轻松地在它们上使用Linq,这使您将来可以毫无问题地更改提供程序。

here is the MSDN on XDocument http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx . 这是XDocument上的MSDN http://msdn.microsoft.com/zh-cn/library/system.xml.linq.xdocument.aspx

I hope this proves to be helpful to you ;-) 希望对您有帮助;-)

Cheers, 干杯,

Max ps lemme know if this is what you needed or not! Max ps lemme知道这是否是您所需要的!

you can use file system.. try to create xml file or csv file in the wpf app directory... 您可以使用文件系统..尝试在wpf应用程序目录中创建xml文件或csv文件...

you can read and write to same file.. so that you can save what ever you want to that file and read from the same file.. 您可以读写同一文件..这样您就可以将所需的内容保存到该文件并从同一文件读取。

If you publish the application through ClickOnce then you can use IsolatedStorage. 如果通过ClickOnce发布应用程序,则可以使用IsolatedStorage。 It is pretty easy to use, just a few lines of code. 它很容易使用,只需几行代码。 You can learn how to use it on WPF isolated storage . 您可以学习如何在WPF隔离存储中使用它。

If you don't publish it through ClickOnce then I would suggest you keep it simple and use static class. 如果您不通过ClickOnce发布它,那么我建议您使其保持简单并使用静态类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM