简体   繁体   中英

Properties.Settings.Default Custom Listtype is not saved!

Hey found out about the settings class Properties.Settings.Default today and saving strings etc. works perfectly fine, though when i want to save a custom List i've created it doesn't work. The list is always null even though there is an entry in the appdata config file with an empty value node. The list is inherited from the ObservableCollection where blabla has a Size (type size) and name (type string) properties. Can someone help me out?

I added

[SettingsSerializeAs(System.Configuration.SettingsSerializeAs.Binary)]

to the property in the settings class (Settings.settings):

[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[SettingsSerializeAs(System.Configuration.SettingsSerializeAs.Binary)]
public global::TestWpfApplication.EtikettDimensionList Dimensions 
{
    get 
    {
        return ((global::TestWpfApplication.EtikettDimensionList)(this["Dimensions"]));
    }
    set
    {
        this["Dimensions"] = value;
    }
}

This will serialize the objects in binary format. If you want XmlFormat you have to implement XML serialization for all classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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