应用程序设置范围 - 用户与应用程序 [英] Application Settings scope - user vs application

查看:37
本文介绍了应用程序设置范围 - 用户与应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个用户级应用程序设置并将其绑定到表单上的文本框,然后在文本框中键入一些内容,该值会自动保存,当应用程序再次启动时,该值会出现在文本框中.当我将设置范围设为应用程序时,不会发生这种情况.

If I create a user level application setting and bind it to a text box on a form, then type something in the textbox, the value is automatically saved and when the application is launched again the value appears in the textbox. This doesn't happen when I scope the setting as application.

为什么应用程序范围的设置不像用户范围的设置那样自动保存?

Why are application scoped settings not saved automatically like user scoped settings are?

如果这是设计使然,我该如何手动保存这些设置并在运行时加载它们?

If this is by design, how can I manually save these settings and load them at runtime?

推荐答案

简而言之,应用程序范围设置不能在运行时更改,而用户范围设置设计为在运行时读取/写入.有多种使用应用程序范围设置的替代方法:

In short, application scoped settings can't be changed at runtime while user scoped settings are designed be read/written at runtime. There are a number of alternatives to using application scoped settings:

  • 使用用户范围的设置
  • 这篇帖子推荐查看 ConfigurationManager 类.
  • 如果您不喜欢用户范围的设置,因为它们没有写入应用程序目录,您可以实现自己的 SettingsProvider 并将它们写入您想要的任何位置
  • Use user scoped settings
  • This post recommends looking into the ConfigurationManager class.
  • If you don't like user scoped settings because they are not written to the application directory you can implementing your own SettingsProvider and have them written where ever you'd like

这篇文章 有一些关于如何最好地管理设置的建议.最后,这里是 Microsoft 的文档关于设置架构有兴趣扩展他们的或推出自己的.

This post has some recommendations on how to best manage settings. Finally, here is Microsoft's documentation on the settings architecture if you're interested in extending theirs or rolling your own.

这篇关于应用程序设置范围 - 用户与应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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