0

background of the program:

I am building an app for windows phone 7 where yo can put in your routine for the week and nutrition plan, so people can have reminders when the go to the gym etc.

each day has a little list of what exercise reps and sets the will do that day. If however they aren't training that day, meaning it's a 'rest day', they press the rest day button and a canvas come up blocking the list with the words rest day on.

The problem is I have the app saving the state of the canvas being down or being up using xml, so that when the user goes back into that page or back into the app the canvas shall be how they left it.

The code i currently have is:

On program load: This checks if when the program was last used whether the user had the rest day canvas up(true) or down(false)

bool searchValueMon;
if (monRest == true)
{
    canMon.Visibility = Visibility.Collapsed;
    mondayReadData();
    IsolatedStorageSettings.ApplicationSettings.Remove("true");
    IsolatedStorageSettings.ApplicationSettings.Save();
}

else

{
    canMon.Visibility = Visibility.Visible;
    IsolatedStorageSettings.ApplicationSettings.Remove("false");
    IsolatedStorageSettings.ApplicationSettings.Save();
}

The Monday's rest button: this puts the canvas up (hiding the list)

       canMon.Visibility = Visibility.Visible;
       monRest = false;

        IsolatedStorageSettings.ApplicationSettings.Add("false", monRest);


        // Write to the Isolated Storage
        XmlWriterSettings x_W_Settings = new XmlWriterSettings();
        x_W_Settings.Indent = true;

        using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (IsolatedStorageFileStream stream = ISF.OpenFile("MonRest.xml", FileMode.Create))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List<Rest>));
                using (XmlWriter xmlWriter = XmlWriter.Create(stream, x_W_Settings))
                {
                    serializer.Serialize(xmlWriter, GenerateMonRestData());
                }
            }
        }

        IsolatedStorageSettings.ApplicationSettings.Remove(Convert.ToString(monRest));
        IsolatedStorageSettings.ApplicationSettings.Save();

the following is the button on the canvas called'exercise' to collapse the canvas ready for a training day:

   private void btnMonEx_Click(object sender, RoutedEventArgs e)
    {
        canMon.Visibility = Visibility.Collapsed;
        //monRest = true;

        // IsolatedStorageSettings.ApplicationSettings.Remove("false");
        IsolatedStorageSettings.ApplicationSettings.Add("true", monRest);

        //IsolatedStorageSettings.ApplicationSettings.Save();

        mondayReadData();


       // IsolatedStorageSettings.ApplicationSettings.Remove(Convert.ToString(monRest));
        IsolatedStorageSettings.ApplicationSettings.Save();

    }

the program doesn't seem to save the state of the canvas at all and when i press either the canvas collapse or to be up, the program crashes.

Any thoughts on what this might be? I am really struggling to find a way of fixing this.

4
  • You're writng to settings, but never reading from them. Keep key names constant, true of false goes inside it. IsolatedStorageSettings.ApplicationSettings.Add("monrest", true); and bool isMonRest = IsolatedStorageSettings.ApplicationSettings["monrest"];
    – Agent_L
    Aug 31, 2012 at 11:32
  • Oh i see. and the line you just mentioned "bool isMonRest = IsolatedStorageSettings.ApplicationSettings["monrest"];" I need to add that somewhere it presume or do i need to change one of the lines i currently have
    – Defterniko
    Aug 31, 2012 at 11:40
  • 1
    I don't know what you have. You posted no code for reading, only for saving one ApplicationSettings key named "true", one key named "false" and one xml file. But there is no reading. BTW, you can put more into ApplicationSettings than just bools or strings. You can do ApplicationSettings["listOfTasks"] = GenerateMonRestData(); to save and List<Rest> savedData = ApplicationSettings["listOfTasks"] as List<Rest>; to read. Leave XML alone, it's too complicated for simple tasks.
    – Agent_L
    Aug 31, 2012 at 11:46
  • 1
    okay thanks very much, i'll look into using something else then for this job
    – Defterniko
    Aug 31, 2012 at 12:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.