-3

A-->B

B+--->A+

Is there anyway to navigate to a second .XAML file and returning back without losing the data on the first one but carry data from the second see the small representation at the top.

4
  • 3
    ...what? What have you tried? Jun 13, 2012 at 15:25
  • Bit broad this - more info would be nice
    – Charleh
    Jun 13, 2012 at 15:27
  • I try NavigationService.GoBack but it just doesnt carry back the data from the B XAML file. Now I am trying to save the data from A to an array and when the user will come back from B to reload them but I believe there is a simplier answer than the way I am trying to do it.
    – Sonamor
    Jun 13, 2012 at 15:28
  • I have a listbox with string values and I want to change the text of some labels above the listbox. What I do to change the labels is to redirect the user with NavigationService.Navigate to a second XAML file where there is a form to set its own text to the labels but when the user comes back the data from the listbox are gone. So I am trying to find a way to change the label text without losing the data from the listbox.
    – Sonamor
    Jun 13, 2012 at 15:30

4 Answers 4

3

Save the state, use ApplicationSettings which gets stored in IsolatedStorage and is what you'd use if you want the data to survive being tombstoned. Or the state can be preserved in transient state.

0
0

By using Server.Urlcode(parameter) parameter value is the value in which you write the special symbols like +,->,&

For Eg: Response.redirect("~/default2.aspx?data" +server.Urlcode(txtdata.text))

1
  • I dont have a problem to return the data from the B to the A I have a problem keeping the same data to the A while trasnfering the data from the B
    – Sonamor
    Jun 13, 2012 at 15:40
0

the way I would do it is to declare some public variables in App.xaml.cs

public partial class App : Application
{
    public var item;

    ...    
}

and refer to them as ((App)(App.Current)).item in any of your pages, that way you have access to the variable in different pages.

(some developers might cringe at the sight of global variables, but hey, it works)

1
  • At last I followed your answer but I knew that it was already there I am still wondering if there is another way to navigate to an another page without losing all the data on the first one (without the NavigateService.GoBack)
    – Sonamor
    Jun 13, 2012 at 22:23
0

All I did at last was saving the listbox in a global string variable and seperate the values by comma, then reading the global streang variable and putting back the data to the listbox.

saving the data to the string

//creating a string array
        string[] scores = new string[lsScore.Items.Count];
        //filling the string array with the data from the listbox
        lsScore.Items.CopyTo(scores, 0);
        //filling a string with the joined values seperated by comma
        string saveScores = string.Join(",", scores);
        //saving the data to the global variable
        saved.saveScores = saveScores;

reading the data from the string

// creating a an array and split the values from the global variable based on the comma
                string[] scores2 = saved.saveScores.Split(',');
                //adding the data to the lsitbox 
                foreach (string str in scores2)
                    lsScore.Items.Add(str);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.