您可以使用查询字符串。当您导航到 TestPage.xaml 时,传入最大计数值
NavigationService.Navigate(new Uri("/TestPage.xaml?maxcount=" + maxCount, UriKind.Relative));
在您的TestPage.xaml 页面中,覆盖OnNavigatedTo 方法并检查传递的查询字符串值。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string maxCount = string.Empty;
if (NavigationContext.QueryString.TryGetValue("maxcount", out maxCount))
{
//parse the int value from the string or whatever you need to do
}
}
或者,您说您已将其存储在独立存储中,因此您也可以从中读取它。查询字符串方法会更快,但如果用户关闭了应用程序,隔离存储方法可以让您稍后再读回它。
根据评论更新
您可以将包含数据的文件存储在独立存储中(您应该添加错误处理)
using(var fs = IsolatedStorageFile.GetUserStoreForApplication())
using(var isf = new IsolatedStorageFileStream("maxCount.txt", FileMode.OpenOrCreate, fs))
using(var sw = new StreamWriter(isf))
{
sw.WriteLine(maxCount.ToString());
}
然后再读一遍
using(var fs = IsolatedStorageFile.GetUserStoreForApplication())
using(var isf = new IsolatedStorageFileStream("maxCount.txt", FileMode.Open, fs))
using(var sr = new StreamReader(isf)
{
string maxCount = sr.ReadToEnd();
//you now have the maxCount value as string
//...
}