1

运行我的应用程序时出现此异常。我导航到 XAML,调试器退出并显示以下消息:

DrawingSurfaceBackgroundGrid 必须是开始绘制的第一个元素。

在 MainPage.xaml 上,当单击 MainPage.xaml 上的按钮时,我导航到此 DirectX.xaml 文件。我确保 DrawingSurfaceBackgroundGrid 是唯一的控件,所以它是第一个元素。我是不是把订单弄错了?(这里还显示了我的 App.xaml 和 MainPage.xaml)

DirectXaml

<phone:PhoneApplicationPage
    x:Class="GameWp8Dx.Hud.Tests.DirectX"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <DrawingSurfaceBackgroundGrid x:Name="DrawingSurfaceBackground" Loaded="DrawingSurfaceBackground_Loaded">
    </DrawingSurfaceBackgroundGrid>

</phone:PhoneApplicationPage>

主页.xaml

<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:local="clr-namespace:GameWp8Dx"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" 
    x:Class="GameWp8Dx.MainPage"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    local:TiltEffect.IsTiltEnabled="True"
    ApplicationBar="{StaticResource socialAppBar}"
    >

    <!--Transitions-->
    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>

<!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot">

        <phone:Panorama x:Name="test" HorizontalAlignment="Left" Height="686" VerticalAlignment="Top" Width="470"
            Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource ResourceKey=LocalizedStrings}}" TitleTemplate="{StaticResource MainPageTitleTemplate}" HeaderTemplate="{StaticResource MainPageHeaderTemplate}">

应用程序.xaml

<Application
    x:Class="GameWp8Dx.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">

    <!--Application Resources-->
    <Application.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="CustomStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <local:LocalizedStrings xmlns:local="clr-namespace:GameWp8Dx" x:Key="LocalizedStrings"/>

            <shell:ApplicationBar x:Key="inGameAppBar" IsVisible="True" IsMenuEnabled="False">
                <shell:ApplicationBarIconButton IconUri="/Assets/Icons/microphone.png" Text="record" Click="record_Click"/>
                <shell:ApplicationBarIconButton IconUri="/Assets/Icons/questionmark.png" Text="info"/>
                <shell:ApplicationBarIconButton IconUri="/Assets/Icons/map.png" Text="map" Click="map_Click"/>            
            </shell:ApplicationBar>
            <shell:ApplicationBar x:Key="socialAppBar" IsVisible="True" IsMenuEnabled="False">
                <shell:ApplicationBarIconButton IconUri="/Assets/Icons/appbar.twitter.png" Text="Tweet" Click="OnTweet"/>
                <shell:ApplicationBarIconButton IconUri="/Assets/Icons/appbar.twitter.bird.png" Text="Tweet" Click="OnTweetSharp"/>
                <shell:ApplicationBarIconButton IconUri="/Assets/Icons/appbar.facebook.png" Text="Share" Click="OnShare"/>
                <shell:ApplicationBarIconButton IconUri="/Assets/Icons/appbar.facebook.heart.png" Text="Like" Click="OnLike"/>
            </shell:ApplicationBar>
        </ResourceDictionary>
    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService
            Launching="Application_Launching" Closing="Application_Closing"
            Activated="Application_Activated" Deactivated="Application_Deactivated"/>
    </Application.ApplicationLifetimeObjects>
</Application>

更新

原来 TransitionFrame() 是罪魁祸首!将其改回 PhoneApplicationPage() 并且 DrawingSurfaceBackgroundGrid 工作顺利。

应用程序.xaml.cs

private void InitializePhoneApplication()
{
    if (phoneApplicationInitialized)
        return;

    // Create the frame but don't set it as RootVisual yet; this allows the splash
    // screen to remain active until the application is ready to render.
    RootFrame = new TransitionFrame();
    //RootFrame = new PhoneApplicationFrame();
    RootFrame.Navigated += CompleteInitializePhoneApplication;

    // Handle navigation failures
    RootFrame.NavigationFailed += RootFrame_NavigationFailed;

    // Handle reset requests for clearing the backstack
    RootFrame.Navigated += CheckForResetNavigation;

    // Ensure we don't initialize again
    phoneApplicationInitialized = true;
}
4

1 回答 1

3

我只是在这里猜测,但是您是否将 RootFrame 更改为特殊的 TransitionFrame?如果是这样,我假设这不适用于 DrawingSurfaceBackgroundGrid。您可能可以更改为 DrarwingSurface 并解决此问题。但是,由于用于与 XAML 交织的中间绘图层,DrawingSurface 对屏幕上显示的所有 DirectX 内容有额外的过度绘制。因此,在整页 D3D 内容上使用 DrawingSurface 可能会出现性能问题(在高清分辨率屏幕上更是如此)。

要了解这个问题,请尝试考虑如果您使用 DrawingSufaceBackgroundGrid 离开页面会发生什么情况?它应该动画吗?如果是这样,您需要将 XAML 动画应用于 D3D 内容,而 DrawingSurfaceBackgroundGrid 不支持该动画。DrawingSurface 支持它,但代价是有一个用于与 XAML 交织的中间绘图层。

我认为在糟糕的 DirectX 性能和缺少页面转换之间进行权衡,我会选择不进行页面转换。话虽如此,不同的应用程序会有不同的妥协。

另一种想法是,您可以根据是否需要全屏 D3D 在标准 PhoneApplicationFrame 和 TransitionFrame 之间切换。我还没有测试过类似的东西。

于 2012-11-15T19:57:13.137 回答