简体   繁体   English

ApplicationSettingsBase不保存嵌套对象

[英]ApplicationSettingsBase does not save nested object

I have this settings class 我有这个设定课程

class AppSettings : ApplicationSettingsBase
{
    [UserScopedSettingAttribute()]        
    public ObservableCollection<TrackViewModel> TracksViewModel
    {
        get { return (ObservableCollection<TrackViewModel>)(this["TracksViewModel"]); }
        set { this["TracksViewModel"] = value; }
    }

... ...

TracksViewModel has a property Track (my Model), which is a class. TracksViewModel具有属性Track(我的模型),它是一个类。 Also this class has a empty constructor, so I guess this make no problem. 此类也有一个空的构造函数,所以我想这没问题。

Anyway, when I save Settings, all the Properties are saved but Track object. 无论如何,当我保存设置时,除了“跟踪”对象外,所有属性都被保存。 In output debug I got no errors. 在输出调试中,我没有任何错误。

Any suggestion ? 有什么建议吗?

How does the appsettings know they type of the ViewModel? 应用程序如何知道它们的ViewModel类型? You may want to check the serialization of that object. 您可能要检查该对象的序列化。

Or, you many want to not use appsettings for this and roll your own xml file for persisting that stuff. 或者,您很多人不想为此使用appsettings并滚动自己的xml文件来保留该内容。

Here are several links: 这里有几个链接:

http://www.codeproject.com/Articles/6730/Custom-Objects-From-the-App-Config-file http://www.codeproject.com/Articles/6730/Custom-Objects-From-the-App-Config-file

How to store class object in app config file 如何在应用程序配置文件中存储类对象

Can I save an object to the app.config file? 我可以将对象保存到app.config文件吗?

How to Read Custom XML from the app.config? 如何从app.config中读取自定义XML?

How to serialize collections in .net 如何在.net中序列化集合

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM