App.paml.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Linq;
  3. using Perspex;
  4. using Perspex.Controls;
  5. using Perspex.Diagnostics;
  6. using Perspex.Markup.Xaml;
  7. using Perspex.Themes.Default;
  8. using Serilog;
  9. namespace ControlCatalog
  10. {
  11. class App : Application
  12. {
  13. public App()
  14. {
  15. RegisterServices();
  16. InitializeSubsystems(GetPlatformId());
  17. InitializeLogging();
  18. Styles = new DefaultTheme();
  19. InitializeComponent();
  20. }
  21. public static void AttachDevTools(Window window)
  22. {
  23. #if DEBUG
  24. DevTools.Attach(window);
  25. #endif
  26. }
  27. static void Main(string[] args)
  28. {
  29. var app = new App();
  30. var window = new MainWindow();
  31. window.Show();
  32. app.Run(window);
  33. }
  34. private void InitializeComponent()
  35. {
  36. PerspexXamlLoader.Load(this);
  37. }
  38. private void InitializeLogging()
  39. {
  40. #if DEBUG
  41. Log.Logger = new LoggerConfiguration()
  42. .MinimumLevel.Error()
  43. .WriteTo.Trace(outputTemplate: "{Message}")
  44. .CreateLogger();
  45. #endif
  46. }
  47. private int GetPlatformId()
  48. {
  49. var args = Environment.GetCommandLineArgs();
  50. if (args.Contains("--gtk"))
  51. {
  52. return (int)PlatformID.Unix;
  53. }
  54. else
  55. {
  56. return (int)Environment.OSVersion.Platform;
  57. }
  58. }
  59. }
  60. }