【问题标题】:Set the default settings value during run-time在运行时设置默认设置值
【发布时间】:2018-01-16 05:41:42
【问题描述】:

我使用 Properties.Settings.Default 来保存我的程序的用户设置。这包括主窗口的大小和位置。见 Picture 在这里。这些代表我调用时分配的默认值

Properties.Settings.Default.Reset();

当我打电话时

Properties.Settings.Default.Height = 25;

例如,通过调用将用户设置保存为 25

Properties.Settings.Default.Save();

当我现在使用 reset() 和 save() 时,我在 Picture 中选择的默认值在调用时再次返回

Properties.Settings.Default.Height;

在运行时如何更改这些默认值,以便在我调用 reset() 时获取我新分配的值? (即使我关闭程序并再次重新打开。它也应该在图片中更新)

【问题讨论】:

  • 我觉得您可能不正确地使用默认值。默认值通常不应在运行时更改,因为它们不再是默认值,而是动态的。
  • 我能否设置动态默认值,例如用户屏幕的大小? @克里斯克鲁兹
  • “如何在运行时更改这些默认值,以便在我调用 reset() 时,我新分配的值被采用?” -- 我不明白你的问题。 Reset() 方法的意义是什么,如果您希望它重置值?如果您想重置这些值,最好不要调用Reset() 而不是尝试将默认值更改为当前设置的值吗?

标签: c# wpf properties settings settings.settings


【解决方案1】:

如果参数范围设置为用户,更改 Settings.Default 应该不是问题。应用范围内的参数是只读的。这是我的设置。

Settings.Default example

然后我在公共字段中使用它进行两种方式的绑定。

public double CurrRateRubToUSD
    {
        get
        {
            return Properties.Settings.Default.CurrencyRateRubToUSD;
        }
        set
        {
            if (value != Properties.Settings.Default.CurrencyRateRubToUSD)
            {
                Properties.Settings.Default.CurrencyRateRubToUSD = value;
                Properties.Settings.Default.Save();
                Properties.Settings.Default.Reload();
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    • 1970-01-01
    • 2015-05-14
    • 2010-09-23
    • 2015-03-13
    相关资源
    最近更新 更多