2 using System
.Collections
.Generic
;
6 using System
.Windows
.Controls
;
7 using System
.Windows
.Documents
;
8 using System
.Windows
.Input
;
9 using System
.Windows
.Media
;
10 using System
.Windows
.Media
.Animation
;
11 using System
.Windows
.Shapes
;
12 using System
.Windows
.Markup
;
14 namespace ApplyTemplateInMeasure
16 public partial class App
: Application
21 this.Startup
+= this.Application_Startup
;
22 this.Exit
+= this.Application_Exit
;
23 this.UnhandledException
+= this.Application_UnhandledException
;
25 InitializeComponent();
28 private void Application_Startup(object sender
, StartupEventArgs e
)
30 this.RootVisual
= new Page();
33 private void Application_Exit(object sender
, EventArgs e
)
37 private void Application_UnhandledException(object sender
, ApplicationUnhandledExceptionEventArgs e
)
39 // If the app is running outside of the debugger then report the exception using
40 // the browser's exception mechanism. On IE this will display it a yellow alert
41 // icon in the status bar and Firefox will display a script error.
42 if (!System
.Diagnostics
.Debugger
.IsAttached
)
45 // NOTE: This will allow the application to continue running after an exception has been thrown
47 // For production applications this error handling should be replaced with something that will
48 // report the error to the website and stop the application.
50 Deployment
.Current
.Dispatcher
.BeginInvoke(delegate { ReportErrorToDOM(e); }
);
53 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e
)
57 string errorMsg
= e
.ExceptionObject
.Message
+ e
.ExceptionObject
.StackTrace
;
58 errorMsg
= errorMsg
.Replace('"', '\'').Replace("\r\n", @"\n");
60 System
.Windows
.Browser
.HtmlPage
.Window
.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg
+ "\");");