CustomEllipse.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Media;
  4. using System.Windows.Controls;
  5. using SHJX.Service.Common.UserColor;
  6. using SHJX.Service.Common.Utils;
  7. namespace SHJX.Service.Library.Views
  8. {
  9. /// <summary>
  10. /// CustomEllipse.xaml 的交互逻辑
  11. /// </summary>
  12. public partial class CustomEllipse : UserControl
  13. {
  14. public CustomEllipse()
  15. {
  16. InitializeComponent();
  17. }
  18. #region Width
  19. public double CapWidth
  20. {
  21. get => (double)GetValue(CapWidthProperty);
  22. set => SetValue(CapWidthProperty, value);
  23. }
  24. public static readonly DependencyProperty CapWidthProperty =
  25. DependencyProperty.Register(
  26. nameof(CapWidth), typeof(double),
  27. typeof(CustomEllipse), new UIPropertyMetadata(0.0, (obj, args) =>
  28. {
  29. var control = obj as CustomEllipse;
  30. var path = control?.cap;
  31. path.Width = Convert.ToDouble(args.NewValue);
  32. }));
  33. #endregion
  34. #region Height
  35. public double CapHeight
  36. {
  37. get => (double)GetValue(CapHeightProperty);
  38. set => SetValue(CapHeightProperty, value);
  39. }
  40. public static readonly DependencyProperty CapHeightProperty =
  41. DependencyProperty.Register(
  42. nameof(CapHeight), typeof(double),
  43. typeof(CustomEllipse), new UIPropertyMetadata(0.0, (obj, args) =>
  44. {
  45. var control = obj as CustomEllipse;
  46. var path = control?.cap;
  47. path.Height = Convert.ToDouble(args.NewValue);
  48. }));
  49. #endregion
  50. #region Fill
  51. public string CapFill
  52. {
  53. get => (string)GetValue(CapFillProperty);
  54. set => SetValue(CapFillProperty, value);
  55. }
  56. public static readonly DependencyProperty CapFillProperty =
  57. DependencyProperty.Register(
  58. nameof(CapFill), typeof(string),
  59. typeof(CustomEllipse), new UIPropertyMetadata(string.Empty, (obj, args) =>
  60. {
  61. var control = obj as CustomEllipse;
  62. var path = control?.cap;
  63. path.Fill = args.NewValue.ToString().ConvertToBrush();
  64. }));
  65. #endregion
  66. #region Stroke
  67. public string CapStroke
  68. {
  69. get => (string)GetValue(CapStrokeProperty);
  70. set => SetValue(CapStrokeProperty, value);
  71. }
  72. public static readonly DependencyProperty CapStrokeProperty =
  73. DependencyProperty.Register(
  74. nameof(CapStroke), typeof(string),
  75. typeof(CustomEllipse), new UIPropertyMetadata(string.Empty, (obj, args) =>
  76. {
  77. var control = obj as CustomEllipse;
  78. var path = control?.cap;
  79. path.Stroke = args.NewValue.ToString().ConvertToBrush();
  80. }));
  81. #endregion
  82. #region StrokeThickness
  83. public double CapStrokeThickness
  84. {
  85. get => (double)GetValue(CapStrokeThicknessProperty);
  86. set => SetValue(CapStrokeThicknessProperty, value);
  87. }
  88. public static readonly DependencyProperty CapStrokeThicknessProperty =
  89. DependencyProperty.Register(
  90. nameof(CapStrokeThickness), typeof(double),
  91. typeof(CustomEllipse), new UIPropertyMetadata(0.0, (obj, args) =>
  92. {
  93. var control = obj as CustomEllipse;
  94. var path = control?.cap;
  95. path.StrokeThickness = Convert.ToDouble(args.NewValue);
  96. }));
  97. #endregion
  98. #region Info
  99. public string Info
  100. {
  101. get => (string)GetValue(InfoProperty);
  102. set => SetValue(InfoProperty, value);
  103. }
  104. public static readonly DependencyProperty InfoProperty =
  105. DependencyProperty.Register(nameof(Info), typeof(string),
  106. typeof(CustomEllipse), new UIPropertyMetadata(string.Empty, (obj, args) =>
  107. {
  108. CustomEllipse control = obj as CustomEllipse;
  109. TextBlock path = control?.txt_info;
  110. path.Text = args.NewValue.ToString();
  111. }));
  112. #endregion
  113. }
  114. }