WPF Properties.Settings 保存和多个用户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22208415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 11:08:21  来源:igfitidea点击:

WPF Properties.Settings saving and multiple users

c#wpfsettingsapplication-settings

提问by Xaphann

In my applications there are some setting saved in the Properties.Settings.Default. These settings can be changed by the user(s) and needs to be saved locally on the computer. While I can save these setting, the problem is that it is only saved for the user currently logged in. Once an user changes a setting it has to be for all users of the computer. How can I accomplish this?

在我的应用程序中有一些设置保存在 Properties.Settings.Default 中。这些设置可由用户更改,并且需要保存在本地计算机上。虽然我可以保存这些设置,但问题是它只为当前登录的用户保存。一旦用户更改设置,它必须为计算机的所有用户保存。我怎样才能做到这一点?

回答by Sheridan

When you open the Settings Designer window in Visual Studio, you have four values that you need to enter for each setting:

在 Visual Studio 中打开“设置设计器”窗口时,需要为每个设置输入四个值:

enter image description here

在此处输入图片说明

You need to set the Scopeproperty to Applicationto have a setting that is the same for all users. For the full story, read the Using Application Settings and User Settingspage on MSDN.

您需要将该Scope属性Application设置为对所有用户都相同的设置。有关完整故事,请阅读MSDN 上的使用应用程序设置和用户设置页面。

回答by thudbutt

User scoped settings are just that, settings that an individual user can change and will only be saved for that user.

用户范围设置只是单个用户可以更改的设置,并且只会为该用户保存。

The application scoped settings will affect all users but they are not designed to be changed by a user.

应用程序范围设置将影响所有用户,但它们并非设计为由用户更改。

You might want to consider a different approach to storing settings that you want users to be able to change but to affect all users of an application e.g. the Windows registry or an external xml file.

您可能需要考虑使用不同的方法来存储您希望用户能够更改但影响应用程序的所有用户的设置,例如 Windows 注册表或外部 xml 文件。

Another option is to use user scoped settings but to change the location to a centralised location so that all users use/save the same settings. See Store user settings into application folderfor an option on how to do this.

另一种选择是使用用户范围设置,但将位置更改为集中位置,以便所有用户使用/保存相同的设置。有关如何执行此操作的选项,请参阅将用户设置存储到应用程序文件夹中。

回答by Rudolfking

Application settings cannot be changed, only by hand before the application is run so I do not recommend that approach.

应用程序设置无法更改,只能在应用程序运行之前手动更改,因此我不推荐这种方法。

In my opinion, propagating the changes may be generally a bad approach. Since this config (user.config) is generally stored in the user's own folder (under Users), it should not be modified by another user (in fact, without administrator acces, another user cannot even access).

在我看来,传播更改通常是一种糟糕的方法。由于这个配置(user.config)一般存放在用户自己的文件夹中(在Users下),所以其他用户不应该修改它(实际上,没有管理员权限,其他用户甚至无法访问)。

I might recommend using other places to store application specific settings: xmlor configfile near your application, or maybe the registry.

我可能会建议使用其他地方来存储特定于应用程序的设置:xmlconfig应用程序附近的文件,或者注册表。

回答by mrSurprise

I would use an external Database for that Stuff... But if you want it quick and simple just save it to a File on the Harddrive (for example C:\Program_Data\\settings.csv) i would use a csv file because it's not much work...

我会为那个东西使用外部数据库......但是如果你想要它快速简单,只需将它保存到硬盘上的文件(例如 C:\Program_Data\\settings.csv)我会使用一个 csv 文件,因为它是没有多少工作...