Using a UserControl in a Windows Phone app instead of a PhoneApplicationPage

Saw a weird problem today – an app would break when navigating to a certain page if it was not running under the debugger. Then I found it was actually navigating forward out of the application and to the Windows Phone home screen and if you tapped the back button – it would return back to the application. I first thought it had something to do with the WebBrowser control that was used inside of it and the fact that the page control was defined in a class library and not the application assembly, but it turned out to be a dead end. Well, what it did turn out is what the post title says – a UserControl was used instead of a PhoneApplicationPage. A navigation request to that control worked, but unless the app was running with a debugger attached – after a few seconds after navigating to that control it would navigate out of the app. After switching it back to be a PhoneApplicationPage – everything just started working!

It reminded me of another common problem with a stack overflow exception just killing an app with no feedback to the user, even when running under the debugger. A StackOverflowException exists, but can’t be caught – an app just immediately exits when it occurs, so be warned! 🙂

Advertisements
Tagged ,

3 thoughts on “Using a UserControl in a Windows Phone app instead of a PhoneApplicationPage

  1. David says:

    This post just led me to fixing an issue I’ve been trying to resolve all day, so thank you for posting this!! I was navigating to a user control via NavigationService. Worked fine when debugging in Visual Studio and when debugging on the phone, but when I deployed the application to the phone the page just exited after about 5 seconds. I find it a bit odd that this isn’t an issue when debugging on the phone.

  2. Natalia says:

    This post just led me to fixing an issue I’ve been trinyg to resolve all day, so thank you for posting this!! I was navigating to a user control via NavigationService. Worked fine when debugging in Visual Studio and when debugging on the phone, but when I deployed the application to the phone the page just exited after about 5 seconds. I find it a bit odd that this isn’t an issue when debugging on the phone.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: