Silverlight 通过枢轴控制非常快速地崩溃
我有一个pivot控件和一个按钮,它没有selectedIndex+,当selectedIndex通过最后一个条目时,它会打开一个消息框,询问用户是否想要测试 但是在测试过程中,如果您对按钮发送垃圾邮件,当您打开MessageBox时,将创建一个0x8000ffff错误 我该如何阻止这种情况发生?这是否与ui线程太忙或继续移动轴心有关?尝试导航出页面后按钮事件是否仍在运行 这就是执行selectedIndex的代码++Silverlight 通过枢轴控制非常快速地崩溃,silverlight,windows-phone-7,Silverlight,Windows Phone 7,我有一个pivot控件和一个按钮,它没有selectedIndex+,当selectedIndex通过最后一个条目时,它会打开一个消息框,询问用户是否想要测试 但是在测试过程中,如果您对按钮发送垃圾邮件,当您打开MessageBox时,将创建一个0x8000ffff错误 我该如何阻止这种情况发生?这是否与ui线程太忙或继续移动轴心有关?尝试导航出页面后按钮事件是否仍在运行 这就是执行selectedIndex的代码++ void gotoNextQuestion() { if (quiz
void gotoNextQuestion()
{
if (quizPivot.SelectedIndex < App.settings.currentTest.Questions.Count() - 1)
{
//xScroll -= scrollAmount;
//moveBackground(xScroll);
if (!stoppedPaging)
{
quizPivot.SelectedIndex++;
}
//App.PlaySoundKey("next");
}
else
{
if (App.settings.testMode == App.TestModes.TrainingRecap)
{
MessageBoxResult result;
if (countAnsweredQuestions() == App.settings.currentTest.Questions.Count())
{
stoppedPaging = true;
result = MessageBox.Show("You have reviewed every training question, would you like to go back to the main menu?", "Training Over", MessageBoxButton.OKCancel);
stoppedPaging = false;
if (result == MessageBoxResult.OK)
{
positionableSpriteRadioButton.IsAnswered -= new Action<bool>(Answers_IsAnsweredCompleted);
spriteRadioButton.IsAnswered -= new Action<bool>(Answers_IsAnsweredCompleted);
App.settings.currentTest = null;
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
return;
}
}
}
else
{
MessageBoxResult result;
if (countAnsweredQuestions() == App.settings.currentTest.Questions.Count())
{
stoppedPaging = true;
result = MessageBox.Show("You have answered all of the questions, are you sure you want to finish?", "Are you sure you want to finish?", MessageBoxButton.OKCancel);
stoppedPaging = false;
}
else
{
checkFinishConditions();
}
}
quizPivot.SelectedIndex = 0;
//App.PlaySoundKey("begin");
}
App.settings.currentTest.currentQuestion = quizPivot.SelectedIndex;
}
void gotoNextQuestion()
{
if(quizPivot.SelectedIndex 有一件事是肯定的
positionableSpriteRadioButton.IsAnswered -= new Action<bool>(Answers_IsAnsweredCompleted);
当你订阅的时候
positionableSpriteRadioButton.IsAnswered += Answers_IsAnsweredCompleted;
这样你就可以再次移除它
但我建议您不要对这种类型的“向导”使用透视。这是对控制的滥用,会给用户带来非常糟糕的体验
此外,仅仅因为您导航到另一个页面,并不意味着代码停止运行。将执行同一表达式中的所有代码,除非在调用NavigationService.Navigate
后添加return
语句
另外,通过包装对NavigationService.Navigation的所有调用,始终确保导航在UI线程上。在调用Dispatcher.BeginInvoke
中导航。如果您在执行selectedIndex++时共享代码,我们可能会建议一种使其更健壮的方法。下面是代码,谢谢。在这种情况下,只有当用户说ok时,我才删除该操作。我似乎已经通过使用begin invoke阻止了崩溃的发生。您根本没有删除任何操作。您完全误解了.NET中引用的工作方式!请参阅更新的答案。
positionableSpriteRadioButton.IsAnswered += Answers_IsAnsweredCompleted;