如果您已经将数据存储到本地存储中,您可以直接在OnNavigatedTo
其他页面的覆盖中读取它。否则,使用导航参数:http ://social.msdn.microsoft.com/Forums/windowsapps/en-US/8cb42356-82bc-4d77-9bbc-ae186990cfd5/passing-parameters-during-navigation-in-windows-8
编辑:我不确定您是否还需要一些有关本地存储的信息。这很简单:Windows.Storage.ApplicationData.Current.LocalSettings
有一个名为 Values 的属性,Dictionary
您可以将设置写入其中。看看http://msdn.microsoft.com/en-us/library/windows/apps/hh700361.aspx
编辑:尝试类似此代码的代码来存储您的列表。
// Try to get the old stuff from local storage.
object oldData = null;
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
bool isFound = settings.Values.TryGetValue("List", out oldData);
// Save a list to local storage. (You cannot store the list directly, because it is not
// serialisable, so we use the detours via an array.)
List<string> newData = new List<string>(new string[] { "test", "blah", "blubb" });
settings.Values["List"] = newData.ToArray();
// Test whether the saved list contains the expected data.
Debug.Assert(!isFound || Enumerable.SequenceEqual((string[]) oldData, newData));
请注意,这只是用于测试的演示代码 - 它没有真正的意义......
编辑:一个建议:不要将列表保留在您的点击处理程序中,因为随着列表的增长,这将变得非常缓慢。我会在导航处理程序中加载并保存列表,即添加类似
protected override void OnNavigatedTo(NavigationEventArgs e) {
base.OnNavigatedTo(e);
if (this.ListBox1.ItemsSource == null) {
object list;
if (ApplicationData.Current.LocalSettings.Values.TryGetValue("List", out list)) {
this.ListBox1.ItemsSource = new List<string>((string[]) list);
} else {
this.ListBox1.ItemsSource = new List<string>();
}
}
}
protected override void OnNavigatedFrom(NavigationEventArgs e) {
if (this.ListBox1.ItemsSource != null) {
ApplicationData.Current.LocalSettings.Values["List"] = this.ListBox1.ItemsSource.ToArray();
}
base.OnNavigatedFrom(e);
}