MainView.xaml.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using Avalonia;
  3. using Avalonia.Controls;
  4. using Avalonia.Markup.Xaml;
  5. using Avalonia.Markup.Xaml.Styling;
  6. using Avalonia.Platform;
  7. using ControlCatalog.Pages;
  8. namespace ControlCatalog
  9. {
  10. public class MainView : UserControl
  11. {
  12. public MainView()
  13. {
  14. this.InitializeComponent();
  15. if (AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetRuntimeInfo().IsDesktop)
  16. {
  17. IList tabItems = ((IList)this.FindControl<TabControl>("Sidebar").Items);
  18. tabItems.Add(new TabItem()
  19. {
  20. Header = "Dialogs",
  21. Content = new DialogsPage()
  22. });
  23. tabItems.Add(new TabItem()
  24. {
  25. Header = "Screens",
  26. Content = new ScreenPage()
  27. });
  28. }
  29. var light = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default'/>");
  30. var dark = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='resm:Avalonia.Themes.Default.Accents.BaseDark.xaml?assembly=Avalonia.Themes.Default'/>");
  31. var themes = this.Find<ComboBox>("Themes");
  32. themes.SelectionChanged += (sender, e) =>
  33. {
  34. switch (themes.SelectedIndex)
  35. {
  36. case 0:
  37. Styles[0] = light;
  38. break;
  39. case 1:
  40. Styles[0] = dark;
  41. break;
  42. }
  43. };
  44. Styles.Add(light);
  45. }
  46. private void InitializeComponent()
  47. {
  48. AvaloniaXamlLoader.Load(this);
  49. }
  50. }
  51. }