locked
How to save string values when navigating to and fro a page in windows apps RRS feed

  • Question

  • Hi,

    I've designed a windows 8 app that will take user-input data from a textbox in one page and show the textbox values in a flipview in another page. The text is showing but when I navigate back and put new values to a textbox it is not added to the other flipview i.e. it just replaces the text that was shown before and I want it to add the text in such a way that it will add a new flipview item allowing the user to see the previous values and the new ones.

    Ive tried using variables and remembering NavigationCache for the page but the values are still being replaced. Here is the code in the BlankPage that contains the flipview:

    protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            //To display values selected from plan meal page
            CustomClass a = (CustomClass)e.Parameter;
    
            string t1="", t2="", t3="", i1="", i2="", i3="", p1="", p2="", p3="";
    
            if (String.IsNullOrEmpty(t1))
            {
                t1 = a.Title;
                i1 = a.Info;
                p1 = a.Place;
    
            }
            else if(String.IsNullOrEmpty(t2))
            {
                t2 = a.Title;
                i2 = a.Info;
                p2 = a.Place;
            }
            else if(String.IsNullOrEmpty(t3))
            {
                t3 = a.Title;
                i3 = a.Info;
                p3 = a.Place;
            }
    
    
                text = new System.Collections.ObjectModel.ObservableCollection<CustomClass>();
    
                text.Add(new CustomClass() { Title = t1, Info = i1, Place = p1 });
                text.Add(new CustomClass() { Title = t2, Info = i2, Place = p2 });
                text.Add(new CustomClass() { Title = t3, Info = i3, Place = p3 }); 
    
            display1.ItemsSource = text;
    
    
        }
    
        public System.Collections.ObjectModel.ObservableCollection<CustomClass> text { get; set; }

    My idea was that if the string t1, i1, p1, was containing a value before I navigated back to the page where I added the text in a texbox, when i enter the new values they will be stored in the other string t2, i2, p2 e.t.c. but it just ends up replacing the first string t1, i1 and p1.

    Would appreciate it if someone could tell me an idea on how to make the new textbox values to be added to a the other strings t2, t3 e.t.c. instead of replacing the previous t1, i1, p1. Or another way to add the textbox values to a new a flipview that will show the previous values and the new ones. Thank you in advance.


    Sunday, July 26, 2015 5:51 AM