ThemePage.axaml.cs 844 B

123456789101112131415161718192021222324252627282930313233
  1. using Avalonia.Controls;
  2. using Avalonia.Markup.Xaml;
  3. using Avalonia.Styling;
  4. namespace ControlCatalog.Pages
  5. {
  6. public partial class ThemePage : UserControl
  7. {
  8. public static ThemeVariant Pink { get; } = new("Pink", ThemeVariant.Light);
  9. public ThemePage()
  10. {
  11. InitializeComponent();
  12. Selector.ItemsSource = new[]
  13. {
  14. ThemeVariant.Default,
  15. ThemeVariant.Dark,
  16. ThemeVariant.Light,
  17. Pink
  18. };
  19. Selector.SelectedIndex = 0;
  20. Selector.SelectionChanged += (_, _) =>
  21. {
  22. if (Selector.SelectedItem is ThemeVariant theme)
  23. {
  24. ThemeVariantScope.RequestedThemeVariant = theme;
  25. }
  26. };
  27. }
  28. }
  29. }