0

I have a wpf app right now where, the user opens an image on a canvas, and they can place colored nodes on it and enter some info about them. Is there a way to save all that data so the next time the user starts the program they can load it all back? I've never worked with .ini or other config files before, so I'm not sure if WPF uses something similar or what.

Yes I've checked this link; Saving the State of a WPF Application Page

and messed around with that code a bit. It can save the xaml and reopen it but nothing else can be done, buttons can't be clicked, canvas can't be clicked, etc. It's basically like the program opens then freezes (but radio buttons can still be switched).

Community
  • 1
  • 1
pfinferno
  • 1,779
  • 3
  • 34
  • 62
  • 1
    Do you *really* need to save off the current XAML, or could you save off the current *state* and the XAML knows how to display that state? – BradleyDotNET Feb 11 '15 at 17:21
  • I guess I'm not really sure what the state actually is. I've read up on some other questions here about saving state, and they all just talk about saving the window size, height, etc. – pfinferno Feb 11 '15 at 17:30
  • 1
    In theory, all that user entered stuff is *data* in your view model, and the view is just representing that (at least, it *should* be). If so, then why not just save off and load that data? – BradleyDotNET Feb 11 '15 at 17:32
  • hmm, I'm reading up on the settings tab under properties. Essentially I would have to make a setting for each piece of data, and change the scope to application? – pfinferno Feb 11 '15 at 17:41
  • Ugh, no. Just serialize it yourself out to a file. Settings is almost definitely *not* the right answer here. This is user generated *data*, not general program settings. – BradleyDotNET Feb 11 '15 at 17:46
  • @BradleyDotNET: `Settings` _might_ be appropriate. It depends on the use case. If the nodes are essentially user-customization of the program's presentation, `Settings` might be the right place. If there is reason to believe a user might want to transfer the data wholesale to a different instance of the program (e.g. on a different computer), then `Settings` probably is _not_ the right place. It just depends. – Peter Duniho Feb 13 '15 at 00:59
  • As far as saving the data generally goes, there's not enough context in the question to know for sure what the right thing to do is. However, note that if you use e.g. [`XmlSerializer`](http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx), you can use that to write either to a `string` (which is easily saved as a single `Settings` value) or to a file. Note that you cannot use `Application` scope with `Settings`...those are effectively read-only. The user can only persist `User` scoped settings. – Peter Duniho Feb 13 '15 at 01:01
  • Thanks for the replies. So it looks like I'll have to serialize every piece of data? Was hoping there was a simple way to do it all at once. – pfinferno Feb 16 '15 at 13:03

0 Answers0