Here is what you need to do: you really need a data layer between UI and persistence. Don't load of store UI in XML; load or store your data layer which you can bind to UI. There are
many other reasons to have a separate data layer. In your case it would be just one or more pure-data classes/structures.
If you want to link UI and XML directly you will lock yourself in hard-coupled rigid settings for UI, XML presentation and data which you won't be able to change in any backward-compatible manner. Don't even play with the idea of making you UI serializeable or something like that. Don't operate XML manually.
If you problem is simple enough, you can make some "manual" data binding: develop a procedure of populating you UI (check boxes set or whatever) from the instance of data and make your UI events modifying an instance of data (for check boxes, use the event
CheckedChanged
; for WPF:
Checked
,
Unchecked
).
(Again, stop giving us hard time! I'm tired of checking APIs for three different libraries! Please, always tag your UI library if you use one.)
Now, what to use for persistence? No doubt, use
Data Contract. See
http://msdn.microsoft.com/en-us/library/ms733127.aspx[
^].
There is no need to use XML manually. Data contract automatically provides a non-intrusive way to store and restore any object graph with practically any data. You only add attributed to your types and their members you need to persist; so your programming is purely declarative here.
Please also see my past answers where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[
^],
Creating a property files...[
^].
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.
If you face any problems, ask a follow-up question; I'll gladly answer.
—SA