ThemePage.axaml.cs 1018 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Markup.Xaml;
  4. using Avalonia.Styling;
  5. namespace ControlCatalog.Pages
  6. {
  7. public class ThemePage : UserControl
  8. {
  9. public static ThemeVariant Pink { get; } = new("Pink", ThemeVariant.Light);
  10. public ThemePage()
  11. {
  12. AvaloniaXamlLoader.Load(this);
  13. var selector = this.FindControl<ComboBox>("Selector")!;
  14. var themeVariantScope = this.FindControl<ThemeVariantScope>("ThemeVariantScope")!;
  15. selector.Items = new[]
  16. {
  17. ThemeVariant.Default,
  18. ThemeVariant.Dark,
  19. ThemeVariant.Light,
  20. Pink
  21. };
  22. selector.SelectedIndex = 0;
  23. selector.SelectionChanged += (_, _) =>
  24. {
  25. if (selector.SelectedItem is ThemeVariant theme)
  26. {
  27. themeVariantScope.RequestedThemeVariant = theme;
  28. }
  29. };
  30. }
  31. }
  32. }