﻿//private void SaveButton_Click_Animation(object sender, EventArgs e)
        //{
        //    NoteTitleFlyOut_Storyboard.Completed += new EventHandler(SaveButton_Click);
        //    NoteTitleFlyOut_Storyboard.Begin();
        //    NavigatingFrom_GrayOut_Storyboard.Begin();

        //    if (PageMode.Equals("edit"))
        //    {
        //        FileIsOpen = false;
        //        myIso = IsolatedStorageFile.GetUserStoreForApplication();
        //        myWriter = new StreamWriter(new IsolatedStorageFileStream(System.IO.Path.Combine(NoteParentFilePath, FileName),
        //                                                                                                    FileMode.Create, // allows file to be overwritten
        //                                                                                                    FileAccess.Write,
        //                                                                                                    myIso));
        //        FileIsOpen = true;
        //    }
        //}

        //private void SaveButton_Click(object sender, EventArgs e)
        //{
        //    NoteTitleFlyOut_Storyboard.Completed -= new EventHandler(SaveButton_Click);
        //    NoteParentFilePath = (NoteParentFilePath == null ? "" : NoteParentFilePath);


        //    // "createnew"
        //    if (PageMode.Equals("createnew"))
        //    {
        //        // Create a new filename using the first several tokens in the file.
        //        GenerateFileName();

        //        (App.Current as App).FileTextForTransfer = NewNoteTextBox.Text;

        //        // Redirect. (filename, text, path, directory) 
        //        NavigationService.Navigate(new Uri((PageMode.Equals("createnew") ? String.Format("/SavingPagesXaml/RequestNoteTitle.xaml?filename={0}&path={1}&directory={2}",
        //                                                                                         FileName,
        //                                                                                         NoteParentFilePath,
        //                                                                                         NoteParentDirectory)
        //                                                                         : "/ViewingFoldersXaml/ListAllNotes.xaml"), UriKind.Relative));
        //    }


        //    // "edit"
        //    else if (PageMode.Equals("edit"))
        //    {
        //        if (FileIsOpen)
        //        {
        //            myWriter.Write(NewNoteTextBox.Text);

        //            // Garbage collection
        //            myWriter.Close();
        //            myWriter.Dispose();
        //            myIso.Dispose();

        //            NavigationService.Navigate(new Uri(String.Format("/ViewingFoldersXaml/ListAllNotes.xaml?filepath={0}&directory={1}",
        //                                                                NoteParentFilePath,
        //                                                                NoteParentDirectory),
        //                                                UriKind.Relative));
        //        }

        //        else
        //        {
        //            SaveButton_Click(sender, e);
        //        }
        //    }
        //}

        //private void GenerateFileName()
        //{
        //    int FileNameLengthInTokens = 5;
        //    try
        //    {
        //        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        //        {
        //            // Declare and initialize variables
        //            char[] Delimiters = { ' ', '\r' };
        //            string[] FileTextByToken = NewNoteTextBox.Text.Split(Delimiters);
        //            StringBuilder myStringBuilder = new StringBuilder();
        //            int FileNameAddition = 1;

        //            // Create a temporary filename for previously unsaved files
        //            for (int i = 0; i <= FileNameLengthInTokens && i < FileTextByToken.Length; i++)
        //            {
        //                myStringBuilder.Append(FileTextByToken[i] + " ");
        //            }

        //            // Check if the file is empty. If it is, prompt whether it should be saved as an empty file.
        //            FileName = myStringBuilder.ToString().Trim();
        //            if (FileName.Equals(""))
        //            {
        //                MessageBoxResult MyResult = MessageBox.Show("This note is currently empty. Would you like to save it as an empty note?", "Save as empty note?", MessageBoxButton.OKCancel);
        //                if (MyResult == MessageBoxResult.Cancel)
        //                {
        //                    NavigationService.Navigate(new Uri("/ViewingFoldersXaml/ListAllNotes.xaml", UriKind.Relative));
        //                }
        //                else
        //                {
        //                    myStringBuilder.Append("Untitled");
        //                    FileName = myStringBuilder.ToString().Trim();
        //                }
        //            }

        //            // Remove InvalidPathChars such as '<' and '>' and '#'
        //            foreach (char InvalidChar in InvalidChars)
        //            {
        //                int IndexOf = FileName.IndexOf(InvalidChar);
        //                if (IndexOf != -1)
        //                {
        //                    FileName = FileName.Remove(IndexOf, 1);
        //                }
        //            }

        //            // Check if the file exists. If it does, find a new filename 
        //            // of the form "OriginalFileName (1).txt"
        //            string ConstantFileName = FileName;
        //            while (myIsolatedStorage.FileExists(System.IO.Path.Combine(NoteParentFilePath, FileName.TrimEnd() + ".txt")))
        //            {
        //                FileName = String.Format("{0} ({1})", ConstantFileName, FileNameAddition);
        //                FileNameAddition++;
        //            }

        //            FileName = (!FileName.ToLower().TrimEnd().EndsWith(".txt") ? FileName + ".txt" : FileName);
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        string message = "The application could make a filename string out of the first " + FileNameLengthInTokens +
        //            "words of the document. Please remove any unusual characters from those tokens, including characters with accents " +
        //            "and any unusual characters.";
        //        MessageBox.Show(message, "Filename creation error", MessageBoxButton.OK);
        //    }
        //}