【发布时间】:2014-05-02 15:59:57
【问题描述】:
我无法解决这个奇怪的问题,我已经尝试了任何我能想到的东西。
我有 5 个页面,每个页面都以这种方式通过导航传递变量:
通过:
NavigationSerice.Navigate(new Uri("/myPage.xaml?key=" + myVariable, UriKind.Relative));
检索:
If (NavigationContext.QueryString.ContainsKey(myKey))
{
String retrievedVariable = NavigationContext.QueryString["myKey"].toString();
}
我在许多页面上打开一个列表,其中一个页面自动从列表中删除一个项目 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");
}
}
}
}
例外:
- _exception {System.ArgumentException:值不在预期范围内。} System.Exception {System.ArgumentException}
我的理论: 应用程序类型加载当前打开和修改的列表。那可能吗?不知道。
【问题讨论】:
-
你能写出它崩溃在哪一行吗?
-
对不起,我没有看到你的消息。明天写:)
标签: c# windows-phone-8 navigation windows-phone isolatedstorage