Shadcn.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using Avalonia;
  3. using Avalonia.Controls.ApplicationLifetimes;
  4. using Avalonia.Markup.Xaml.Styling;
  5. using Avalonia.Media;
  6. using Avalonia.Styling;
  7. using SukiUI.Controls;
  8. using SukiUI.Models;
  9. namespace SukiUI.Theme.Shadcn
  10. {
  11. public static class Shadcn
  12. {
  13. public static void Configure(Application application, ThemeVariant startupTheme)
  14. {
  15. Application.Current.Resources.MergedDictionaries.Add(new ResourceInclude(new Uri("avares://SukiUI/Theme/Shadcn/BlackWhiteTheme.axaml")
  16. )
  17. {
  18. Source = new Uri("avares://SukiUI/Theme/Shadcn/BlackWhiteTheme.axaml")
  19. });
  20. var whiteTheme = new SukiColorTheme("White", new Color(255, 255, 255, 255), new Color(255, 255, 255, 255));
  21. var blackTheme = new SukiColorTheme("Black", new Color(255, 0, 0, 0), new Color(255, 0, 0, 0));
  22. SukiTheme.GetInstance().AddColorThemes(new []{whiteTheme, blackTheme});
  23. var BlackStyles = new StyleInclude(new Uri("avares://SukiUI/Theme/Shadcn/ShadDarkStyles.axaml"))
  24. {
  25. Source = new Uri("avares://SukiUI/Theme/Shadcn/ShadDarkStyles.axaml")
  26. };
  27. SukiTheme.GetInstance().OnBaseThemeChanged += variant =>
  28. {
  29. if (variant == ThemeVariant.Dark)
  30. {
  31. application.Styles.Add(BlackStyles);
  32. SukiTheme.GetInstance().ChangeColorTheme(whiteTheme);
  33. }
  34. else
  35. {
  36. SukiTheme.GetInstance().ChangeColorTheme(blackTheme);
  37. application.Styles.Remove(BlackStyles);
  38. }
  39. };
  40. try
  41. {
  42. ((SukiWindow)((ClassicDesktopStyleApplicationLifetime)application.ApplicationLifetime).MainWindow)
  43. .BackgroundShaderFile = "backgroundshadcn";
  44. }catch{}
  45. SukiTheme.GetInstance().ChangeBaseTheme(ThemeVariant.Light);
  46. SukiTheme.GetInstance().ChangeBaseTheme(ThemeVariant.Dark);
  47. SukiTheme.GetInstance().ChangeBaseTheme(startupTheme);
  48. }
  49. }
  50. }