MainView.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.FluentDark;
  39. break;
  40. case 1:
  41. Application.Current.Styles[0] = App.FluentLight;
  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. var transparencyLevels = this.Find<ComboBox>("TransparencyLevels");
  58. transparencyLevels.SelectionChanged += (sender, e) =>
  59. {
  60. if (VisualRoot is Window window)
  61. window.TransparencyLevelHint = (WindowTransparencyLevel)transparencyLevels.SelectedIndex;
  62. };
  63. }
  64. protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
  65. {
  66. base.OnAttachedToVisualTree(e);
  67. var decorations = this.Find<ComboBox>("Decorations");
  68. if (VisualRoot is Window window)
  69. decorations.SelectedIndex = (int)window.SystemDecorations;
  70. }
  71. }
  72. }