Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm writing a Golf Handicap program in WPF and using xml files to store the Course and score data.
If I create another course and then open the window that displays the information, it has not updated. If I close the program and reopen, I can open the display window and it shows the new course data.
Is there a way that it will update without closing and reopening the program?
Posted

1 solution

You have faced the problem of data persistence. You don't really need to work with XML directly. The best way to persist data in XML is the Data Contract:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

This approach is the easiest to use and most non-intrusive, too. You should have your data in some set of pure-data classes or structures; and you can hold your data in many objects of those types making a graph of any kind, which does not even has to be a tree (it means, if you have circular dependencies quite typical in relational model), it's fine. You simply tell the data contract serialize to store the objects in any file or stream, and later you will be able to restore all these objects at once. You don't need to modify your types in any way (you don't need to inherit certain types, implement certain interface, make anything public, nothing), you only add couple attributes to your types and members. Performance is very good, too, due to automatic generation of serialization assemblies from metadata on the fly, based on System.Reflection.Emit.

Please see my past answers where I advocated this approach:
Creating property files...[^],
How can I utilize XML File streamwriter and reader in my form application?[^].

—SA
 
Share this answer
 

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