Don't save or load controls. Have a data layer made of pure data classes and have a procedures for populating UI from the model and updating model form UI. Think "controller" or "data binding". The effort of adding this extra layer will pay off pretty soon.
When you do it, saving a data model anywhere won't be a problem. If you want to persist data in a file/stream, there is nothing better than
Data Contract.
See
http://msdn.microsoft.com/en-us/library/ms733127.aspx[
^].
See also my past solutions advocating Data Contract approach:
How can I utilize XML File stream writer and reader in my form application?[
^],
Creating property files...[
^],
deseralize a json string array[
^].
[EDIT]
JayShim wrote:
I appreciate your help very much. May I have more help on your suggestion? How can I use "controller or data binding"?
Certainly, but the answers would go well beyond the format of CodeProject Quick Questions & Answers.
First, by "controller" I mean an the architectural component as it is understood in the
Model–View–Controller (MVC)
architectural pattern. Read about it:
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller[
^],
http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[
^].
From the first of the above two links, you will be able to find further references to some MVC frameworks available for .NET, but you can also just use the architectural approach itself. Also, as you use WPF, pay attention to another architectural pattern called Model View ViewModel (MVVM) which is largely based on MVC and mostly targeted to be used with WPF or Silverlight. Please see:
http://en.wikipedia.org/wiki/MVVM[
^],
http://code.msdn.microsoft.com/How-to-implement-MVVM-71a65441[
^],
http://wpf.codeplex.com/wikipage?title=WPF%20Model-View-ViewModel%20Toolkit&referringTitle=Home[
^],
some frameworks:
http://cinch.codeplex.com/[
^].
In the first of the articles referenced below, you will find other Open-Source frameworks based on MVVM.
Now, about data binding. This is a widely uses conception used in WFP, Silverlight,
System.Windows.Forms
, ASP.NET and other libraries. As you work with WPF, start here:
http://msdn.microsoft.com/en-us/library/ms750612.aspx[
^].
Good luck,
—SA