locked
Storing data and passing it between screens + more. RRS feed

  • Question

  • Hey,

     

    More questions am afraid.

     

    I have several xml files that each describe a questionnaire structure. I am loading them using "sample data" functionality in Blend and then generating GUI components via code so that the user can fill in the questions. all the questionnaires have their own screen. All good so far.

    Now I have to create a main screen that has a button for each questionnaire (hub and spokes UI pattern). The user can choose one questionnaire and fill it in and then return to this main screen. For now that is enough, but soon it will have to be so that the user can fill many of the same type of questionnaires.

    Because the user will have to be able to go back to the already filled in questionnaire section, I will have to store the data for the time that the application runs. How would I go about this? Program structure wise? I know I will have to add an array for each questionnaire type and create some methods that can be used to access and manipulate them. But where should I add these? In App.xaml.cs?

    I already tried adding some new methods and properties to App.xaml.cs but could not figure out how to access them from the separate screens? Application.current...? Might be something very simple again.

     

    Sorry for the long post but it's rather hard to describe the problem. And I have several more questions coming up... 

     

    Thank you. :)

     

    ps. If you happen to know if it's easy to save the sample data back into a xml file on hard drive let me know... 

     

     

    Monday, April 12, 2010 6:54 AM

Answers

  • As you have discovered, you can't reference app.xaml.cs from SketchFlow screens. Because the screens are in a separate assembly that the main application references, you can't reference back to the main assembly, or you would create a loop in the references.

    If you were to create static data structures in your screens assembly, they would be available to all screens, and have a lifetime the same as app.xaml.cs items.  Just create a class there, and mark the members you want to use as static.

    • Marked as answer by hokoosha Monday, April 12, 2010 4:16 PM
    Monday, April 12, 2010 3:11 PM
    Moderator

All replies

  • Hmn, the main problem seems to be related to namespaces. Sketchflow places the "screens" in a different namespace than the App.xaml.cs file I need to access. There seems to be a few standard ways of doing what I described above, for exmaple casting the Application.current to App. I just can't access the App class from the screens.cs. What do I need to add/change?

     

    Cheers! :)

    Monday, April 12, 2010 2:24 PM
  • As you have discovered, you can't reference app.xaml.cs from SketchFlow screens. Because the screens are in a separate assembly that the main application references, you can't reference back to the main assembly, or you would create a loop in the references.

    If you were to create static data structures in your screens assembly, they would be available to all screens, and have a lifetime the same as app.xaml.cs items.  Just create a class there, and mark the members you want to use as static.

    • Marked as answer by hokoosha Monday, April 12, 2010 4:16 PM
    Monday, April 12, 2010 3:11 PM
    Moderator
  • Oh, ok. It will take a good while to wrap my head around all these new things and how WPF/XAML assemblies and whatnot works. 

     

    Chuck, your method worked perfectly. Cheers! I have a nagging feeling in the back of my head that I should have thought that solution on my own, but I guess I was way too caught up with the impossible App way of doing things.

     

    Thanks again. :) 

    Monday, April 12, 2010 4:16 PM
  • If I wasn't clear, the app.xaml.cs method would work if it were not a SketchFlow project, so you were on the right track for a general WPF/SL application.
    Monday, April 12, 2010 4:20 PM
    Moderator