Няма описание

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Navigation;
  5. namespace ViewShotExample.Net46
  6. {
  7. /// <summary>
  8. /// Provides application-specific behavior to supplement the default Application class.
  9. /// </summary>
  10. public partial class App : Application
  11. {
  12. private readonly AppReactPage _reactPage = new AppReactPage();
  13. /// <summary>
  14. /// Initializes the singleton application object. This is the first line of authored code
  15. /// executed, and as such is the logical equivalent of main() or WinMain().
  16. /// </summary>
  17. public App()
  18. {
  19. }
  20. /// <summary>
  21. /// Override method fired prior to the Startup event when the Run method of the Application object is called...
  22. /// </summary>
  23. /// <param name="e"></param>
  24. protected override void OnStartup(StartupEventArgs e)
  25. {
  26. base.OnStartup(e);
  27. OnCreate(e.Args);
  28. }
  29. /// <summary>
  30. /// Called whenever the app is opened to initialized...
  31. /// </summary>
  32. /// <param name="arguments"></param>
  33. private void OnCreate(string[] arguments)
  34. {
  35. var shellWindow = Application.Current.MainWindow;
  36. if (shellWindow == null)
  37. {
  38. shellWindow = new Window
  39. {
  40. ShowActivated = true,
  41. ShowInTaskbar = true,
  42. Title = "ViewShotExample.Net46",
  43. Height = 768,
  44. Width = 1024,
  45. WindowStartupLocation = WindowStartupLocation.CenterScreen
  46. };
  47. Application.Current.MainWindow = shellWindow;
  48. }
  49. //Show Window if it is not already active...
  50. if (!shellWindow.IsLoaded)
  51. {
  52. shellWindow.Show();
  53. }
  54. var rootFrame = shellWindow.Content as Frame;
  55. // Do not repeat app initialization when the Window already has content,
  56. // just ensure that the window is active
  57. if (rootFrame == null)
  58. {
  59. _reactPage.OnCreate(arguments);
  60. // Create a Frame to act as the navigation context and navigate to the first page
  61. rootFrame = new Frame();
  62. rootFrame.NavigationFailed += OnNavigationFailed;
  63. // Place the frame in the current Window
  64. shellWindow.Content = rootFrame;
  65. }
  66. if (rootFrame.Content == null)
  67. {
  68. // When the navigation stack isn't restored navigate to the first page,
  69. // configuring the new page by passing required information as a navigation
  70. // parameter
  71. rootFrame.Content = _reactPage;
  72. }
  73. // Ensure the current window is active
  74. shellWindow.Activate();
  75. }
  76. /// <summary>
  77. /// Invoked when Navigation to a certain page fails
  78. /// </summary>
  79. /// <param name="sender">The Frame which failed navigation</param>
  80. /// <param name="e">Details about the navigation failure</param>
  81. private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
  82. {
  83. throw new Exception("Failed to load Page...");
  84. }
  85. }
  86. }