XNA / XAML混合项目中的Windows Phone Toolkit挂起应用程序

时间:2013-03-12 19:27:38

标签: windows-phone-7 windows-phone-8

在XNA / XAML混合项目中使用Windows Phone Toolkit中的任何控件会在某些条件下挂起应用程序:

  1. 创建“Windows Phone XAML和XNA App”项目

  2. 输入以下命令为WP Toolkit添加Silverlight:

    Install-Package SilverlightToolkitWP -Version 4.2012.6.25
    
    包管理器控制台中的

  3. 在MainPage.xaml中添加toolkit命名空间:

    <phone:PhoneApplicationPage
    ...
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    ...>
    
  4. 从工具包添加任何控件,例如。 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. 在WP8设备或WP8模拟器上运行应用程序(在WP7上此问题不存在)

  6. 点击“更改为游戏页面”按钮

  7. 锁定并解锁屏幕或切换到另一个应用程序然后返回。

  8. 点击后退按钮返回主页

  9. 点击TimePicker并尝试更改时间。

  10. 应用程序未被终止,但UI被阻止

  11. 我读到WP8以100%兼容性运行WP7应用程序,但似乎这不是真的......

2 个答案:

答案 0 :(得分:0)

这不是WP8工具包的正确版本。截至目前,您应该使用https://nuget.org/packages/WPtoolkit(2012年10月版,版本4.2012.10.30)

答案 1 :(得分:0)

我终于找到了这个bug的解决方案!它很容易修复,但很难发现。以下是您必须在OnNavigatedFrom(NavigationEventArgs e)方法中添加到游戏页面类的代码行。您必须添加此if声明:

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);
}