PageRenderTime 45ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/Quickstarts/MultiTargeting/Silverlight/RealEstateListingViewer/App.xaml.cs

#
C# | 100 lines | 53 code | 8 blank | 39 comment | 1 complexity | 46c24c8070dcc73aa399ae9fc71eff48 MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. //===================================================================================
  18. // Microsoft patterns & practices
  19. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  20. //===================================================================================
  21. // Copyright (c) Microsoft Corporation. All rights reserved.
  22. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  23. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  24. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  25. // FITNESS FOR A PARTICULAR PURPOSE.
  26. //===================================================================================
  27. // The example companies, organizations, products, domain names,
  28. // e-mail addresses, logos, people, places, and events depicted
  29. // herein are fictitious. No association with any real company,
  30. // organization, product, domain name, email address, logo, person,
  31. // places, or events is intended or should be inferred.
  32. //===================================================================================
  33. using System;
  34. using System.Collections.Generic;
  35. using System.Linq;
  36. using System.Net;
  37. using System.Windows;
  38. using System.Windows.Controls;
  39. using System.Windows.Documents;
  40. using System.Windows.Input;
  41. using System.Windows.Media;
  42. using System.Windows.Media.Animation;
  43. using System.Windows.Shapes;
  44. using RealEstateListingViewer.Models;
  45. using RealEstateListingViewer.Services;
  46. using RealEstateListingViewer.Views;
  47. namespace RealEstateListingViewer
  48. {
  49. public partial class App : Application
  50. {
  51. public App()
  52. {
  53. this.Startup += this.Application_Startup;
  54. this.Exit += this.Application_Exit;
  55. this.UnhandledException += this.Application_UnhandledException;
  56. InitializeComponent();
  57. }
  58. private void Application_Startup(object sender, StartupEventArgs e)
  59. {
  60. RealEstateListingPresentationModel model = new RealEstateListingPresentationModel();
  61. this.RootVisual = model.View as UIElement;
  62. }
  63. private void Application_Exit(object sender, EventArgs e)
  64. {
  65. }
  66. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
  67. private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
  68. {
  69. // If the app is running outside of the debugger then report the exception using
  70. // the browser's exception mechanism. On IE this will display it a yellow alert
  71. // icon in the status bar and Firefox will display a script error.
  72. if (!System.Diagnostics.Debugger.IsAttached)
  73. {
  74. // NOTE: This will allow the application to continue running after an exception has been thrown
  75. // but not handled.
  76. // For production applications this error handling should be replaced with something that will
  77. // report the error to the website and stop the application.
  78. e.Handled = true;
  79. try
  80. {
  81. string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
  82. errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
  83. System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
  84. }
  85. catch (Exception)
  86. {
  87. }
  88. }
  89. }
  90. }
  91. }