我使用c#在VS2010中创建一个项目,我有一个字符串值,我当前正在写入项目的Properties.settings。
我有时候在关闭我的机器并重新启动时,该值看起来好像没有保存?
另一种可能性是,当我将我的代码提交给SVN时,可能已经编写了vallue aint。
所以有人可以帮我确认一下,
当我将字符串值写入Properties.Settings时,这只是暂时的吗?我最终还是要将它转换为文本文件或其他内容吗?
请非常感谢有关此事的信息。
先谢谢;)
答案 0 :(得分:1)
答案 1 :(得分:0)
d:\用户\机器人\应用程序数据\本地\ DataCrea \ WorkShifts.exe_Url_4ssvgihryk04nltgkxam4dh4bdhymcqa \ 0.9.28.0 \ user.config
每次命令后都应保存属性:
Properties.Settings.Default.Save();
我不确定以下事情是否会影响您的问题,但最好添加布尔属性CallUpgrade = True。然后在主构造函数中添加以下行:
//upgrade properties, if version was increased
if (Settings.Default.CallUpgrade)
{
Settings.Default.Upgrade();
Settings.Default.CallUpgrade = false;
Settings.Default.Save();
}
... Upgrade()将确保从先前版本正确迁移设置。
答案 2 :(得分:0)
如果您拨打Properties.Settings.Default.Save();
以下是我用来记住Window的位置和大小的一些代码:
<Window x:Class="my_namespace.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:my_namespace"
Closing="save_position"
Height="{Binding Source={x:Static local:Properties.Settings.Default}, Path=height, Mode=TwoWay}"
Width="{Binding Source={x:Static local:Properties.Settings.Default}, Path=width, Mode=TwoWay}"
Top="{Binding Source={x:Static local:Properties.Settings.Default}, Path=top, Mode=TwoWay}"
Left="{Binding Source={x:Static local:Properties.Settings.Default}, Path=left, Mode=TwoWay}">
在后面的代码中有这个:
private void save_position(object sender, CancelEventArgs e)
{
Properties.Settings.Default.Save();
}