我正在尝试将窗口的位置保存为用户设置,以便我可以在应用程序启动时恢复它。我使用这种类型的设计器添加一个设置:
using System.Configuration;
namespace MyApp.Framework
{
[SettingsSerializeAs(SettingsSerializeAs.Xml)]
public class SavedWindowSettings
{
public double Left { get; set; }
public double Top { get; set; }
public SavedWindowSettings()
{
}
public SavedWindowSettings(double left, double top)
{
Left = left;
Top = top;
}
}
}
它可以编译,但是当我运行时我得到
System.NotImplementedException: 'The method or operation is not implemented.'
但调用堆栈中的最后一件事是
PresentationFramework.dll!System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(System.Windows.Baml2006.Baml2006SchemaContext.BamlType bamlType, short typeId)
这没有多大帮助。我认为这与 App.config 有关。如果我将设置的类型更改为字符串,我的 App.config 就会
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
and
<userSettings>
<MyApp.Properties.Settings>
<setting name="MainWindowPlacement" serializeAs="String">
<value />
</setting>
</MyApp.Properties.Settings>
</userSettings>
部分。我尝试将它们添加回来,改变serializeAs
to xml
,同样的例外。我缺少什么?