CircleProgressBar.axaml.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Data;
  4. using Avalonia.Markup.Xaml;
  5. namespace SukiUI.Controls
  6. {
  7. public partial class CircleProgressBar : UserControl
  8. {
  9. public CircleProgressBar()
  10. {
  11. InitializeComponent();
  12. }
  13. private void InitializeComponent()
  14. {
  15. AvaloniaXamlLoader.Load(this);
  16. }
  17. private double _value = 50;
  18. public double Value
  19. {
  20. get => _value;
  21. set
  22. {
  23. _value = (int)(value * 3.6);
  24. SetValue(ValueProperty,_value);
  25. }
  26. }
  27. /// <summary>
  28. /// Defines the <see cref="Value"/> property.
  29. /// </summary>
  30. public static readonly StyledProperty<double> ValueProperty =
  31. AvaloniaProperty.Register<CircleProgressBar, double>(nameof(Value), defaultValue: 50, coerce: (o, d) => d * 3.6);
  32. public static readonly StyledProperty<int> HeightProperty =
  33. AvaloniaProperty.Register<CircleProgressBar, int>(nameof(Height), defaultValue: 150);
  34. public int Height
  35. {
  36. get { return GetValue(HeightProperty); }
  37. set { SetValue(HeightProperty, value); }
  38. }
  39. public static readonly StyledProperty<int> WidthProperty =
  40. AvaloniaProperty.Register<CircleProgressBar, int>(nameof(Width), defaultValue: 150);
  41. public int Width
  42. {
  43. get { return GetValue(WidthProperty); }
  44. set { SetValue(WidthProperty, value); }
  45. }
  46. public static readonly StyledProperty<int> StrokeWidthProperty =
  47. AvaloniaProperty.Register<CircleProgressBar, int>(nameof(StrokeWidth), defaultValue: 10);
  48. public int StrokeWidth
  49. {
  50. get { return GetValue(StrokeWidthProperty); }
  51. set { SetValue(StrokeWidthProperty, value); }
  52. }
  53. public static readonly StyledProperty<bool> IsIndeterminateProperty =
  54. AvaloniaProperty.Register<CircleProgressBar, bool>(nameof(IsIndeterminate), false);
  55. public bool IsIndeterminate
  56. {
  57. get => GetValue(IsIndeterminateProperty);
  58. set => SetValue(IsIndeterminateProperty, value);
  59. }
  60. }
  61. }