[英]How to check navigation status on WP7
I am writing an automated test suite for my WP7 app. 我正在为WP7应用程序编写一个自动化测试套件。 Currently it fails when I try to execute several commands in a row, where one command is a navigation command and second command an email task.
目前,当我尝试连续执行多个命令时,它会失败,其中一个命令是导航命令,第二个命令是电子邮件任务。
So the question is how do I determine if WP7 is in progress of navigating between two pages? 因此,问题是如何确定WP7是否正在进行在两个页面之间导航?
Edit: 编辑:
Command itself is created not in the code behind but in a separate class. 命令本身不是在后面的代码中创建的,而是在单独的类中创建的。
Code looks like this: 代码如下:
Command 1: 指令1:
private void BuildContactCommand()
{
var contactCmd = new RelayCommand(() =>
// Command
{
var ecTask = new EmailComposeTask();
// composing message here
// Command fails here
ecTask.Show();
},
// Can Execute
() => !_isNavigating
);
_appCmdProvier.Register(contactCmd, CommandsNames.ContactSupportCmd);
}
Command 2: 指令2:
private void BuildNavigateToDetailsCommand()
{
var navToDetailsCmd = new RelayCommand<string>
(
appId => NavigateTo("/Pages/AppDetails/AppDetailsPage.xaml?appId=" + appId)
);
_appCmdProvier.Register(navToDetailsCmd, CommandsNames.NavigateToDetailsCmd);
}
Just found a solution. 刚刚找到解决方案。
private void TrackNavigationStatus()
{
var root = Application.Current.RootVisual as PhoneApplicationFrame;
root.Navigating += (s, e) => _isNavigating = true;
root.Navigated += (s, e) => _isNavigating = false;
root.NavigationFailed += (s, e) => _isNavigating = false;
root.NavigationStopped += (s, e) => _isNavigating = false;
}
Let me know if there is a cleaner way to do it. 让我知道是否有一种更清洁的方法。
The OnNavigatedFrom
event should be called when you're leaving the first page. 当您离开首页时,应调用
OnNavigatedFrom
事件。 But if you schedule both on the dispatcher, I wouldn't think any errors should occur. 但是,如果您同时在调度程序上进行调度,我认为不会发生任何错误。
Post the code that's causing the error? 发布导致错误的代码?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.