raphi011
raphi011

Reputation: 502

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?

Upvotes: 2

Views: 1102

Answers (1)

Emond
Emond

Reputation: 50672

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.

Upvotes: 3

Related Questions