1
我在我的WP7应用程序中有一个ErrorPage.xaml页面。当发生未处理的异常时,将调用app.xaml.cs中的方法,并将异常传递给ErrorPage.xaml.cs,并通过链接将错误显示给用户,以返回主页面。
如果我点击AppBar IconButton的速度太快,导致失败事件被引发,errorpage仍然被调用,但没有任何内容显示在错误页面上。 AppBar是唯一可见的东西。wp7错误处理
想不通为什么
这里是我的app.xaml.cs代码
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
e.Handled = true;
ErrorPage.Exception = e.ExceptionObject;
(RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Source =
new Uri(Navigation.PAGE_ERROR, UriKind.Relative);
}
Error.xaml是这样
<Grid x:Name="LayoutRoot" Background="{StaticResource GlobalPageBackgroundBrush}" CacheMode="BitmapCache">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,24,0,12">
<TextBlock x:Name="ApplicationTitle" Text="{StaticResource AppName}" Style="{StaticResource PhoneTextNormalStyle}" FontWeight="SemiBold"/>
<TextBlock x:Name="PageTitle" Text="error" Margin="-3,-8,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1">
<TextBlock x:Name="ErrorText" Style="{StaticResource PhoneTextTitle3Style}" TextWrapping="Wrap" />
<StackPanel x:Name="FriendlyErrorStackPanel" Margin="0,100,0,0" Orientation="Vertical">
<TextBlock Style="{StaticResource PhoneTextTitle3Style}" TextWrapping="Wrap">
<TextBlock.Text>
Please click the link below to return to the main page of the application.
</TextBlock.Text>
</TextBlock>
<HyperlinkButton Style="{StaticResource PhoneHyperlinkStyle}" Content="Start Over" NavigateUri="/Views/MainPage.xaml" />
</StackPanel>
</Grid>
</Grid>
,最后的errorPage。 xaml.cs是
public partial class ErrorPage : PhoneApplicationPage
{
public ErrorPage()
{
InitializeComponent();
}
public static Exception Exception;
// Executes when the user navigates to this page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (Exception != null)
{
if (System.Diagnostics.Debugger.IsAttached)
{
FriendlyErrorStackPanel.Visibility = System.Windows.Visibility.Collapsed;
ErrorText.Text = Exception.ToString();
}
else
{
FriendlyErrorStackPanel.Visibility = System.Windows.Visibility.Visible;
ErrorText.Text = GlobalConstants.DEFAULT_ERROR_MESSAGE;
}
}
base.OnNavigatedTo(e);
}
}
我担心的是,您正在从这个错误页面导航**正向**回主。这意味着你可以按下_back_ 2x,并且可能回到错误状态? – 2010-12-07 19:08:10