Click here to Skip to main content
15,918,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using WPF in VB. My window contains radio buttons and combo boxes. I am wondering how can I save those in textfiles? Would you help me?
Posted

1 solution

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
 
Share this answer
 
v2
Comments
JayShim 29-Nov-11 11:45am    
I appreciate your help very much. May I have more help on your suggestion? How can I use "controller or data binding"?
Sergey Alexandrovich Kryukov 30-Nov-11 20:40pm    
Sure. That goes deep and would require a big article on each topic, if not a book. So, I can only give you some reference to start with. Using further references in the articles I referenced you can find everything from introductions to code samples and sample projects. Please see my updated solution above, after [EDIT].
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900