views:

52

answers:

0

I'm having a problem with PageFunction navigation. After OnReturn is called an ExecutionEngineException is thrown.

"Exception of type 'System.ExecutionEngineException' was thrown."

I create and navigate to my PageFunction as follows:

 void ShowPageFunction2(){
     mPageFunction2 = new PageFunction2(...);
     mPageFunction2.Return += new System.Windows.Navigation.ReturnEventHandler<StudyDescription>(PageFunction2_Return);  
     mMainScreen.MainWindowContent.NavigationService.Navigate(mPageFunction2); 
 } 

 void PageFunction2_Return(object sender, System.Windows.Navigation.ReturnEventArgs<CStudyDescription> e) {            
     if(e != null){
         // Do something.
     }
 }

The above is in a controller class that maintains references to the various Pages as well as the main Window. mMainScreen is a Window that contains only a Frame (MainWindowContent).

PageFunction2 contains the following event handler:

    private void button1_Click(object sender, RoutedEventArgs e) { 
        OnReturn(null);            
    }

Running the debugger shows that the exception is thrown when I step past the closing brace of the event handler that calls OnReturn.

I've found that if a Page (not the controller class) creates, navigates to, and handles the return event for the PageFunction it seems to work. Although, I can't do this to solve my problem. So is it that in the failing situation, the code to handle the navigation and return is not within a UI element? Is that what is causing the exception?