导航而不会丢失数据

时间:2012-06-13 15:24:17

标签: windows-phone-7 windows-phone-7.1 windows-phone

A - >乙

B + --->一种+

无论如何导航到第二个.XAML文件并返回而不会丢失第一个上的数据但是从第二个数据中携带数据会看到顶部的小表示。

4 个答案:

答案 0 :(得分:3)

保存状态,使用存储在IsolatedStorage中的ApplicationSettings,如果您希望数据能够被逻辑删除,那么您就可以使用它。或者状态可以保存在transient state

答案 1 :(得分:0)

使用Server.Urlcode(参数)参数值是您编写特殊符号的值,如+, - >,&

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

答案 2 :(得分:0)

我这样做的方法是在App.xaml.cs中声明一些公共变量

public partial class App : Application
{
    public var item;

    ...    
}

并将它们称为((App)(App.Current))。在您的任何页面中的项目,这样您就可以访问不同页面中的变量。

(有些开发人员可能会因为看到全局变量而感到畏缩,但是嘿,它有效)

答案 3 :(得分:0)

我最后做的就是将列表框保存在全局字符串变量中,并用逗号分隔值,然后读取全局的streang变量并将数据放回列表框。

将数据保存到字符串

//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;

从字符串中读取数据

// 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);
相关问题