locked
How to save image source and timer interval? RRS feed

  • Question

  • Hi everyone,

    I'm trying to save the source of an image and the interval of a timer (timer1.Interval = TimeSpan.FromSeconds(1);) so that when the user opens the app for the second time, the image is the saved one and and the timer has the right interval but I just can't get it to work. I'm using the following pieces of code:

                 ApplicationData.Current.LocalSettings.Values["Image"] = image1.Source;
    
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Image"))
                    image1.Source = (BitmapSource)ApplicationData.Current.LocalSettings.Values["Image"];

    and:

       ApplicationData.Current.LocalSettings.Values["Timer"] = timer1.Interval;
    
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Timer"))
                    timer1.Interval = (int)ApplicationData.Current.LocalSettings.Values["Timer"];
    The user saves it by clicking on a button by the way. Button releases only the following codes:
    ApplicationData.Current.LocalSettings.Values["Timer"] = timer1.Interval;
    ApplicationData.Current.LocalSettings.Values["Image"] = image1.Source;
    Is there a way to save the image source and the timer interval?



    • Edited by N-Joki Tuesday, February 5, 2013 2:24 PM
    Monday, February 4, 2013 1:04 PM

Answers

  • I got it in a different way but it works. Thanks anyway.
    • Marked as answer by N-Joki Thursday, February 14, 2013 6:11 PM
    Thursday, February 14, 2013 6:10 PM

All replies

  • Anyhow, there is a typo in: timer1.Interval = (BitmapSource)ApplicationData.Current.LocalSettings.Values["Timer"];

    Monday, February 4, 2013 1:25 PM
  • Thanks for pointing that out.
    Monday, February 4, 2013 1:48 PM
  • Hi,

    The LocalSettings can only store the data that can be serialized/deserialized. You could try to save the path of the image and the value of ther Interval.


    Aaron
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 6, 2013 9:45 AM
  • I got it in a different way but it works. Thanks anyway.
    • Marked as answer by N-Joki Thursday, February 14, 2013 6:11 PM
    Thursday, February 14, 2013 6:10 PM