Is it possible to persist a WPF Control, or any other non-trivial object to a *.settings file in a .NET application? I figured this would be easy since the *.settings file allows me to specify an atrbitrary type for each individual settings, unfortunately, it does not appear to be functioning for me.
What I am trying to do is to persist a System.Windows.Controls.ListBox to my application's *.settings file. The problem is, my listbox instance is not actually being saved. When I go to run my application again, it is just null when I go to load it.
Here is what I am using to load/save my ListBox instance
private void PersistListBoxToSettings(System.Windows.Controls.ListBox projectsListBox)
{
Properties.Settings.Default.ListBoxData = projectsListBox;
Properties.Settings.Default.Save();
}
private void LoadProjectListBox()
{
projectsListBox = Properties.Settings.Default.ListBoxData; // Always null after application restart.
}
I tested my *.settings file to ensure that it was even working by saving/loading a simple string - that functioned as expected.
Is what I am trying to do just a really bad idea? Should I stop trying to be clever and use proper object serialization to disk?