Question

I am writing an automated test suite for my WP7 app. 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?

Edit:

Command itself is created not in the code behind but in a separate class.

Code looks like this:

Command 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:

    private void BuildNavigateToDetailsCommand()
    {
        var navToDetailsCmd = new RelayCommand<string>
            (
                appId => NavigateTo("/Pages/AppDetails/AppDetailsPage.xaml?appId=" + appId)
            );
        _appCmdProvier.Register(navToDetailsCmd, CommandsNames.NavigateToDetailsCmd);
    }
Was it helpful?

Solution

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.

OTHER TIPS

The OnNavigatedFrom event should be called when you're leaving the first page. But if you schedule both on the dispatcher, I wouldn't think any errors should occur.

Post the code that's causing the error?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top