Don't serialize controls! Serialize data model.
You need to have a separate data layer and bind it with the UI controls. The UI will be populated based on data and the data will be updated by the user's manipulation with the UI.
You can serialize the whole data layers at once, if it is relatively small. The best way to do it is using
Data Contract and
System.Runtime.Serialization.DataContractSerializer
.
See:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx[
^].
This is a very robust, easy-to-use and universal approach. You don't have to work with XML manually; all you do is adding attributes to type and members, such as
[DataContract]
and
[DataMembers]
to describe a contract.
You can store and restore the whole object graph, even if it contains circular references (that is, not a tree but a more general graph).
Please see my past solutions where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[
^],
Creating a property files...[
^].
Also, I suggest you learn and analyze applicability of the following
architectural patterns (
http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[
^]):
MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],
MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),
MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],
MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.
—SA