C# - 在 WPF 应用程序中保存用户设置的方法? [英] C# - approach for saving user settings in a WPF application?

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

问题描述

您建议采用什么方法在 WPF 窗口(桌面)应用程序中保留用户设置?请注意,这个想法是用户可以在运行时更改他们的设置,然后可以关闭应用程序,然后在稍后启动应用程序时,应用程序将使用当前设置.实际上,它看起来好像应用程序设置没有改变.

What approach do you recommend for persisting user settings in a WPF windows (desktop) application? Note that the idea is that the user can change their settings at run time, and then can close down the application, then when starting up the application later the application will use the current settings. Effectively then it will appear as if the application settings do not change.

Q1 - 数据库或其他方法?我确实有一个无论如何都会使用的 sqlite 数据库,因此在数据库中使用表与任何方法一样好?

Q1 - Database or other approach? I do have a sqlite database that I will be using anyway hence using a table in the database would be as good as any approach?

Q2 - 如果数据库:什么数据库表设计?一张表,其中包含可能具有的不同数据类型的列(例如,stringlongDateTime 等)或仅包含一个字符串的表您必须序列化和反序列化值的值?我在想第一个会更容易,如果设置不多,开销也不大?

Q2 - If Database: What database table design? One table with columns for different data types that one might have (e.g. string, long, DateTime etc) OR just a table with a string for the value upon which you have to serialize and de-serialize the values? I'm thinking the first would be easier, and if there aren't many settings the overhead isn't much?

Q3 - 应用程序设置可以用于此目的吗?如果是这样,是否需要执行任何特殊任务才能在此处启用持久性?在这种情况下,在应用程序设置设计器中使用默认"值会发生什么?默认值会覆盖在运行应用程序之间保存的任何设置吗?(或者你不需要使用默认值)

Q3 - Could Application Settings be used for this? If so are there any special tasks required to enable the persistence here? Also what would happen regarding usage of the "default" value in the Application Settings designer in this case? Would the default override any settings that were saved between running the application? (or would you need to NOT use the default value)

推荐答案

您可以使用 应用程序设置 对此,考虑到读取和写入设置所消耗的时间(特别是如果您使用 Web 服务),使用数据库并不是最佳选择.

You can use Application Settings for this, using database is not the best option considering the time consumed to read and write the settings(specially if you use web services).

这里有几个链接解释了如何实现这一点并在 WPF 中使用它们 -

Here are few links which explains how to achieve this and use them in WPF -

WPF 中的用户设置

快速 WPF 提示:如何绑定到 WPF 应用程序资源和设置?

WPF 的可配置窗口

这篇关于C# - 在 WPF 应用程序中保存用户设置的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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