当用户退出配置表单(不是我的主表单)时,我正在尝试保存我的应用程序设置。它将设置保存在内存中,因为当我再次打开表单时,我配置的数据仍然存在,但不会将其保存到磁盘。这是将 xml 文件保存到的文件路径
C:\Users\david_000\AppData\Local[公司名称][项目名称]\1.0.0.0.
我在实现 ApplicationSettingsBase 文件的类中使用 [UserScopedSetting()],因此它应该在我调用时保存,
Properties.Settings.Default.Save();
这是我使用 ApplicationSettingsBase 的课程
public class DeviceConfiguration : ApplicationSettingsBase
{
/// <summary>
/// Initializes a new instance of the <see cref="DeviceConfiguration"/> class.
/// </summary>
public DeviceConfiguration()
: base()
{
this.MasterDevices = new BindingList<Device>();
this.SlaveDevices = new BindingList<Device>();
}
[UserScopedSetting()]
[SettingsSerializeAs(System.Configuration.SettingsSerializeAs.Xml)]
public BindingList<Device> MasterDevices
{
get
{
return this["MasterDevices"] as BindingList<Device>;
}
set
{
this["MasterDevices"] = value;
}
}
[UserScopedSetting()]
[SettingsSerializeAs(System.Configuration.SettingsSerializeAs.Xml)]
public BindingList<Device> SlaveDevices
{
get
{
return this["SlaveDevices"] as BindingList<Device>;
}
set
{
this["SlaveDevices"] = value;
}
}
}
我的 BindingList 包含多个属性,并且该类使用 [Serializable] 属性。但是当我保存 xml 文件时,它保存的只是:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<userSettings>
<[company.project].Properties.Settings>
<setting name="IpAddressBESS" serializeAs="String">
<value>192.168.3.254</value>
</setting>
<setting name="PortBESS" serializeAs="String">
<value>504</value>
</setting>
<setting name="IpAddressInverter" serializeAs="String">
<value>192.168.3.200</value>
</setting>
<setting name="PortInverter" serializeAs="String">
<value>502</value>
</setting>
<setting name="StartDate" serializeAs="String">
<value>04/08/2015 08:00:00</value>
</setting>
<setting name="EndDate" serializeAs="String">
<value>04/08/2015 16:00:00</value>
</setting>
<setting name="DeviceConfig" serializeAs="Xml">
<value />
</setting>
</[company.project].Properties.Settings>
</userSettings>
</configuration>
对此的任何建议将不胜感激。