App.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using Avalonia;
  5. using Avalonia.Controls;
  6. using Avalonia.Controls.Templates;
  7. using Avalonia.Markup.Xaml;
  8. using Avalonia.Styling;
  9. using Avalonia.Themes.Default;
  10. using Avalonia.Diagnostics;
  11. using Avalonia.Platform;
  12. using Avalonia.Shared.PlatformSupport;
  13. using Avalonia.Media;
  14. namespace TestApplication
  15. {
  16. public class App : Application
  17. {
  18. public App()
  19. {
  20. // TODO: I believe this has to happen before we select sub systems. Can we
  21. // move this safely into Application itself? Is there anything in here
  22. // that is platform specific??
  23. //
  24. RegisterServices();
  25. }
  26. public void Run()
  27. {
  28. Styles.Add(new DefaultTheme());
  29. var loader = new AvaloniaXamlLoader();
  30. var baseLight = (IStyle)loader.Load(
  31. new Uri("resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"));
  32. Styles.Add(baseLight);
  33. Styles.Add(new SampleTabStyle());
  34. DataTemplates = new DataTemplates
  35. {
  36. new FuncTreeDataTemplate<Node>(
  37. x => new TextBlock {Text = x.Name},
  38. x => x.Children),
  39. };
  40. MainWindow.RootNamespace = "TestApplication";
  41. var wnd = MainWindow.Create();
  42. wnd.AttachDevTools();
  43. Run(wnd);
  44. }
  45. // This provides a simple UI tree for testing input handling, drawing, etc
  46. public static Window CreateSimpleWindow()
  47. {
  48. Window window = new Window
  49. {
  50. Title = "Avalonia Test Application",
  51. Background = Brushes.Red,
  52. Content = new StackPanel
  53. {
  54. Margin = new Thickness(30),
  55. Background = Brushes.Yellow,
  56. Children = new Controls
  57. {
  58. new TextBlock
  59. {
  60. Text = "TEXT BLOCK",
  61. Width = 300,
  62. Height = 40,
  63. Background = Brushes.White,
  64. Foreground = Brushes.Black
  65. },
  66. new Button
  67. {
  68. Content = "BUTTON",
  69. Width = 150,
  70. Height = 40,
  71. Background = Brushes.LightGreen,
  72. Foreground = Brushes.Black
  73. }
  74. }
  75. }
  76. };
  77. return window;
  78. }
  79. }
  80. }