我无法解决这个奇怪的问题,我已经尝试过任何我能想到的东西。
我有5页页面,每个页面都以这种方式通过导航传递变量:
通行证:
NavigationSerice.Navigate(new Uri("/myPage.xaml?key=" + myVariable, UriKind.Relative));检索:
If (NavigationContext.QueryString.ContainsKey(myKey))
{
String retrievedVariable = NavigationContext.QueryString["myKey"].toString();
}我在多个页面上打开一个列表,其中一个页面会自动从list actualProject中删除一个项(actualProject是字符串列表的一个变量)。然后,当我回到如此遥远的地方,我到达一个特定的页面-应用程序抛出一个异常。为什么?我没有头绪。
删除该项的代码:
// Remove the active subject from the availible subjects
unlinkedSubjects.Remove(actualSubject);
unlinkedsubjectsListBox.ItemsSource = null;
unlinkedsubjectsListBox.ItemsSource = unlinkedSubjects;然后抛出异常的OnNavigatedTo事件的页面:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (NavigationContext.QueryString.ContainsKey("key"))
{
actualProject = NavigationContext.QueryString["key"];
try
{
//Read subjectList from IsolatedStorage
subjectList = readSetting(actualProject) != null ? (List<String>)readSetting(actualProject) : new List<String>();
//Put the subjectList into the subjectListBox
subjectListBox.ItemsSource = subjectList;
//Set the subjectsPageTitle to the "actualProject" value, to display the name of the current open project at the top of the screen
subjectsPageTitle.Text = actualProject;
}
catch (Exception)
{
if (language.Equals("en."))
{
// Language is set to english
MessageBox.Show("Couldn't open the project, please try again or please report the error to Accelerated Code - details on the about page");
}
else if (language.Equals("no."))
{
// Language is set to norwegian
MessageBox.Show("Kunne ikke åpne prosjektet, vennligst prøv igjen eller rapporter problemet til Accelerated Code - du finner detaljer på om-siden");
}
}
}
}例外:
我的理论:是一种加载当前打开和修改列表的应用程序。这有可能吗?不知道。
发布于 2014-05-02 18:31:46
因此,有许多方法可以在页面之间传递数据。
你选择的方式是最不明智的。
您可以使用PhoneApplicationService.Current字典 --但是如果你有大量的变量,在应用程序关闭后不会一直存在,并且可以简化,这也是很麻烦的。
我编写了一个自由的DLL,它将这个精确的场景记在脑海中,称为EZ_iso。
你都能在这找到你的需要
从根本上说,你要做的就是使用它。
[DataContractAttribute]
public class YourPageVars{
[DataMember]
public Boolean Value1 = false;
[DataMember]
public String Value2 = "And so on";
[DataMember]
public List<String> MultipleValues;
}一旦您有了类设置,您就可以轻松地在页面之间传递它。
YourPageVars vars = new YourPageVars { /*Set all your values*/ };
//Now we save it
EZ_iso.IsolatedStorageAccess.SaveFile("PageVars",vars);就这样!现在您可以导航和检索该文件。
YourPageVars vars = (YourPageVars)EZ_iso.IsolatedStorageAccess.GetFile("PageVars",typeof(YorPageVars));这很好,因为您可以使用它进行更多的导航。您可以将它用于任何需要隔离存储的地方。这些数据现在被序列化到设备上,所以即使应用程序关闭,它也将保持不变。当然,如果您选择的话,也可以随时删除该文件。
如果有任何异常,请务必参考文档。如果你还需要帮助,可以在twitter、@Anth0nyRussell或amr@AnthonyRussell.info上给我打电话。
https://stackoverflow.com/questions/23432303
复制相似问题