2012-11-15 82 views
1

我在運行我的應用程序時遇到此異常。我導航到一個XAML和調試器退出出此消息:例外:DrawingSurfaceBackgroundGrid必須是開始繪製的第一個元素

DrawingSurfaceBackgroundGrid必須開始 繪圖的第一個元素。

在我的MainPage.xaml上,當在MainPage.xaml上單擊按鈕時,我導航到此DirectX.xaml文件。我確信DrawingSurfaceBackgroundGrid是唯一的控件,所以它是第一個元素。我訂單錯了嗎? (另外這裏顯示的是我的App.xaml和MainPage.xaml中)

DirectX.xaml

<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> 

MainPage.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}"> 

的App.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> 

UPDATE

原來TransitionFrame()是罪魁禍首!將其更改回PhoneApplicationPage()並且DrawingSurfaceBackgroundGrid工作順利。

App.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; 
} 

回答

3

我只是猜測這裏,但你改變RootFrame一個特殊的TransitionFrame?如果是這樣,我假設這不適用於DrawingSurfaceBackgroundGrid。您可以更改爲DrarwingSurface並解決此問題。但是由於用於與XAML交互的中間繪圖層,DrawingSurface會對屏幕上顯示的所有DirectX內容進行額外重繪。因此,在整頁D3D內容上使用DrawingSurface可能會出現性能問題(在高清分辨率屏幕上更是如此)。

要理解問題,請嘗試考慮如果使用DrawingSufaceBackgroundGrid從頁面導航離開會發生什麼?它應該動畫嗎?如果是這樣,您需要將XAML動畫應用於D3D內容,並且不支持DrawingSurfaceBackgroundGrid。它支持DrawingSurface,但是需要使用中間繪圖層來與XAML交互。

我認爲,在糟糕的DirectX性能和缺少頁面轉換之間的折衷方案中,我會選擇不進行頁面轉換。話雖如此,不同的應用程序將有不同的妥協。

另一種想法是,根據您是否需要全屏D3D,您可能可以在標準PhoneApplicationFrame和TransitionFrame之間切換。我還沒有測試過這樣的東西。

+0

感謝JustinAngel,結果發現團隊中的某個人將RootFrame從PhoneApplicationFrame改爲了TransitionFrame。這是一個相當的折衷,我喜歡那些頁面轉換。但你最後的想法很有趣,我必須嘗試。 – Lisa

+0

嗨賈斯汀,什麼是用於與XAML交織的中間圖層。你能解釋更多關於這個嗎? –

相關問題