0
votes

Using any control from Windows Phone Toolkit in XNA/XAML hybrid project hangs application under certain conditions:

  1. Create "Windows Phone XAML and XNA App" project

  2. Add Silverlight for WP Toolkit by typing:

    Install-Package SilverlightToolkitWP -Version 4.2012.6.25
    

    in Package Manager Console

  3. In MainPage.xaml add toolkit namespace:

    <phone:PhoneApplicationPage
    ...
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    ...>
    
  4. Add any control from toolkit eg. TimePicker:

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <!--Create a single button to navigate to the second page which is rendered with the XNA Framework-->
        <Button Height="100" Content="Change to game page" Click="Button_Click" />
        <toolkit:TimePicker />
    </Grid>
    
  5. Run app on WP8 device or WP8 emulator (on WP7 this problem doesn't exist)

  6. Click "Change to game page" button

  7. Lock and unlock screen or switch to another app then return.

  8. Click back button to return to MainPage

  9. Click on TimePicker and try to change time.

  10. Application isn't killed but UI is blocked

I read that WP8 runs WP7 apps in 100% compatibility but it seems this isn't true...

2
I found that I don't need to use toolkit controls to reproduce this bug. Simple TextBox is also hanging application.gumis

2 Answers

0
votes

I finally found the solution for this bug! It's very easy to fix but was difficult to discover. Here's the line of code you have to add to your game page class in OnNavigatedFrom(NavigationEventArgs e) method. You have to add this if statement:

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    // Stop the timer
    timer.Stop();

    // Set the sharing mode of the graphics device to turn off XNA rendering
    if (e.IsNavigationInitiator)
        SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false);
    base.OnNavigatedFrom(e);
}
0
votes

That's not the right version of the toolkit for WP8. As of now you should use https://nuget.org/packages/WPtoolkit (October 2012 version, version 4.2012.10.30)