运行我的应用程序时出现此异常。我导航到 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;
}