CommandBarCustomizationPage.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Avalonia.Controls;
  2. using Avalonia.Media;
  3. namespace ControlCatalog.Pages
  4. {
  5. public partial class CommandBarCustomizationPage : UserControl
  6. {
  7. public CommandBarCustomizationPage()
  8. {
  9. InitializeComponent();
  10. }
  11. private void OnBgPresetChanged(object? sender, SelectionChangedEventArgs e)
  12. {
  13. if (LiveBar == null)
  14. return;
  15. switch (BgPresetCombo.SelectedIndex)
  16. {
  17. case 1:
  18. LiveBar.Background = new SolidColorBrush(Color.Parse("#0078D4"));
  19. break;
  20. case 2:
  21. LiveBar.Background = new SolidColorBrush(Color.Parse("#1C1C1E"));
  22. break;
  23. case 3:
  24. LiveBar.Background = new LinearGradientBrush
  25. {
  26. StartPoint = new Avalonia.RelativePoint(0, 0, Avalonia.RelativeUnit.Relative),
  27. EndPoint = new Avalonia.RelativePoint(1, 0, Avalonia.RelativeUnit.Relative),
  28. GradientStops =
  29. {
  30. new GradientStop(Color.Parse("#3F51B5"), 0),
  31. new GradientStop(Color.Parse("#E91E63"), 1)
  32. }
  33. };
  34. break;
  35. case 4:
  36. LiveBar.Background = Brushes.Transparent;
  37. break;
  38. default:
  39. LiveBar.ClearValue(BackgroundProperty);
  40. break;
  41. }
  42. }
  43. private void OnFgChanged(object? sender, SelectionChangedEventArgs e)
  44. {
  45. if (LiveBar == null)
  46. return;
  47. switch (FgCombo.SelectedIndex)
  48. {
  49. case 1:
  50. LiveBar.Foreground = Brushes.White;
  51. break;
  52. case 2:
  53. LiveBar.Foreground = Brushes.Black;
  54. break;
  55. default:
  56. LiveBar.ClearValue(ForegroundProperty);
  57. break;
  58. }
  59. }
  60. private void OnRadiusChanged(object? sender, Avalonia.Controls.Primitives.RangeBaseValueChangedEventArgs e)
  61. {
  62. if (LiveBar == null)
  63. return;
  64. var r = (int)RadiusSlider.Value;
  65. LiveBar.CornerRadius = new Avalonia.CornerRadius(r);
  66. RadiusLabel.Text = $"{r}";
  67. }
  68. private void OnBorderChanged(object? sender, Avalonia.Controls.Primitives.RangeBaseValueChangedEventArgs e)
  69. {
  70. if (LiveBar == null)
  71. return;
  72. var t = (int)BorderSlider.Value;
  73. LiveBar.BorderThickness = new Avalonia.Thickness(t);
  74. BorderLabel.Text = $"{t}";
  75. if (t > 0)
  76. LiveBar.BorderBrush = Brushes.Gray;
  77. else
  78. LiveBar.BorderBrush = null;
  79. }
  80. }
  81. }