MainView.xaml.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections;
  3. using Avalonia;
  4. using Avalonia.Controls;
  5. using Avalonia.Markup.Xaml;
  6. using Avalonia.Markup.Xaml.MarkupExtensions;
  7. using Avalonia.Markup.Xaml.Styling;
  8. using Avalonia.Markup.Xaml.XamlIl;
  9. using Avalonia.Platform;
  10. using ControlCatalog.Pages;
  11. namespace ControlCatalog
  12. {
  13. public class MainView : UserControl
  14. {
  15. public MainView()
  16. {
  17. AvaloniaXamlLoader.Load(this);
  18. if (AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetRuntimeInfo().IsDesktop)
  19. {
  20. IList tabItems = ((IList)this.FindControl<TabControl>("Sidebar").Items);
  21. tabItems.Add(new TabItem()
  22. {
  23. Header = "Dialogs",
  24. Content = new DialogsPage()
  25. });
  26. tabItems.Add(new TabItem()
  27. {
  28. Header = "Screens",
  29. Content = new ScreenPage()
  30. });
  31. }
  32. var themes = this.Find<ComboBox>("Themes");
  33. themes.SelectionChanged += (sender, e) =>
  34. {
  35. switch (themes.SelectedIndex)
  36. {
  37. case 0:
  38. Application.Current.Styles[0] = App.FluentLight;
  39. break;
  40. case 1:
  41. Application.Current.Styles[0] = App.FluentDark;
  42. break;
  43. case 2:
  44. Application.Current.Styles[0] = App.DefaultLight;
  45. break;
  46. case 3:
  47. Application.Current.Styles[0] = App.DefaultDark;
  48. break;
  49. }
  50. };
  51. var decorations = this.Find<ComboBox>("Decorations");
  52. decorations.SelectionChanged += (sender, e) =>
  53. {
  54. if (VisualRoot is Window window)
  55. window.SystemDecorations = (SystemDecorations)decorations.SelectedIndex;
  56. };
  57. }
  58. protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
  59. {
  60. base.OnAttachedToVisualTree(e);
  61. var decorations = this.Find<ComboBox>("Decorations");
  62. if (VisualRoot is Window window)
  63. decorations.SelectedIndex = (int)window.SystemDecorations;
  64. }
  65. }
  66. }