SampleDetailControl.xaml.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System.Windows;
  2. using System.Windows.Media;
  3. using System.Windows.Controls;
  4. using SHJX.Service.Common.UserColor;
  5. using SHJX.Service.Common.Utils;
  6. namespace SHJX.Service.Library.Views
  7. {
  8. /// <summary>
  9. /// UserControl1.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class SampleDetailControl : UserControl
  12. {
  13. #region
  14. public string CurrentName
  15. {
  16. get => (string)GetValue(CurrentNameProperty);
  17. set => SetValue(CurrentNameProperty, value);
  18. }
  19. public static readonly DependencyProperty CurrentNameProperty =
  20. DependencyProperty.Register(
  21. nameof(CurrentName), typeof(string),
  22. typeof(SampleDetailControl), new UIPropertyMetadata(string.Empty, (obj, args) =>
  23. {
  24. var control = obj as SampleDetailControl;
  25. control.Name = args.NewValue.ToString();
  26. }));
  27. #endregion
  28. #region 控件编号
  29. public string CurrentTagNo
  30. {
  31. get => (string)GetValue(CurrentTagNoProperty);
  32. set => SetValue(CurrentTagNoProperty, value);
  33. }
  34. public static readonly DependencyProperty CurrentTagNoProperty =
  35. DependencyProperty.Register(
  36. nameof(CurrentTagNo), typeof(string),
  37. typeof(SampleDetailControl), new UIPropertyMetadata(string.Empty, CurrentTagNoChangedCallback)
  38. );
  39. private static void CurrentTagNoChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args)
  40. {
  41. var control = obj as SampleDetailControl;
  42. var path = control.btn_TagNo;
  43. path.Content = args.NewValue.ToString();
  44. }
  45. #endregion
  46. #region 顶部详细信息
  47. public string CurrentDetailInfo
  48. {
  49. get => (string)GetValue(CurrentDetailInfoProperty);
  50. set => SetValue(CurrentDetailInfoProperty, value);
  51. }
  52. public static readonly DependencyProperty CurrentDetailInfoProperty =
  53. DependencyProperty.Register(
  54. nameof(CurrentDetailInfo), typeof(string),
  55. typeof(SampleDetailControl), new UIPropertyMetadata(string.Empty, CurrentDetailInfoChangedCallback)
  56. );
  57. private static void CurrentDetailInfoChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args)
  58. {
  59. var control = obj as SampleDetailControl;
  60. var path = control.txt_detail;
  61. path.Text = args.NewValue.ToString();
  62. }
  63. #endregion
  64. #region 顶部颜色
  65. public string CurrentTagColor
  66. {
  67. get => (string)GetValue(CurrentTagColorProperty);
  68. set => SetValue(CurrentTagColorProperty, value);
  69. }
  70. public static readonly DependencyProperty CurrentTagColorProperty =
  71. DependencyProperty.Register(
  72. nameof(CurrentTagColor), typeof(string),
  73. typeof(SampleDetailControl), new UIPropertyMetadata(string.Empty, CurrentTagColorChangedCallBack)
  74. );
  75. private static void CurrentTagColorChangedCallBack(DependencyObject obj, DependencyPropertyChangedEventArgs args)
  76. {
  77. var control = obj as SampleDetailControl;
  78. var path = control?.UserControlTag;
  79. path.Background = args.NewValue.ToString().ConvertToBrush();
  80. }
  81. #endregion
  82. #region 体积
  83. public string CurrentVolume
  84. {
  85. get => (string)GetValue(CurrentVolumeProperty);
  86. set => SetValue(CurrentVolumeProperty, value);
  87. }
  88. public static readonly DependencyProperty CurrentVolumeProperty =
  89. DependencyProperty.Register(
  90. nameof(CurrentVolume), typeof(string),
  91. typeof(SampleDetailControl), new UIPropertyMetadata(string.Empty, CurrentVolumeChangedCallback)
  92. );
  93. private static void CurrentVolumeChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args)
  94. {
  95. var control = obj as SampleDetailControl;
  96. var path = control?.txt_volume;
  97. path.Text = args.NewValue.ToString();
  98. }
  99. #endregion
  100. #region 结果
  101. public string CurrentResult
  102. {
  103. get => (string)GetValue(CurrentResultProperty);
  104. set => SetValue(CurrentResultProperty, value);
  105. }
  106. public static readonly DependencyProperty CurrentResultProperty =
  107. DependencyProperty.Register(
  108. nameof(CurrentResult), typeof(string),
  109. typeof(SampleDetailControl), new UIPropertyMetadata(string.Empty, (obj, args) =>
  110. {
  111. var control = obj as SampleDetailControl;
  112. var path = control?.txt_result;
  113. path.Text = args.NewValue.ToString();
  114. }));
  115. #endregion
  116. #region ResultColor
  117. public string ResultColor
  118. {
  119. get => (string)GetValue(ResultColorProperty);
  120. set => SetValue(ResultColorProperty, value);
  121. }
  122. public static readonly DependencyProperty ResultColorProperty = DependencyProperty.Register(
  123. nameof(ResultColor), typeof(string), typeof(SampleDetailControl), new UIPropertyMetadata("#000000", ResultColorChangedCallback));
  124. private static void ResultColorChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args)
  125. {
  126. var control = obj as SampleDetailControl;
  127. var path = control.txt_result;
  128. path.Foreground = args.NewValue.ToString().ConvertToBrush();
  129. }
  130. #endregion
  131. public SampleDetailControl()
  132. {
  133. InitializeComponent();
  134. }
  135. private void ChooseMode_Click(object sender, RoutedEventArgs e)
  136. {
  137. GeneralTransform gt = ChooseMode.TransformToAncestor(Application.Current.MainWindow!);
  138. Point pt = gt.Transform(new Point(0, 0));
  139. Rect rc = SystemParameters.WorkArea;//获取工作区大小
  140. ModeSetting setting = new(Name)
  141. {
  142. WindowStartupLocation = WindowStartupLocation.Manual
  143. };
  144. if (pt.Y + setting.Height > rc.Height)
  145. {
  146. pt.Y = rc.Height - (setting.Height + 10);
  147. }
  148. if (pt.X + setting.Width > rc.Width)
  149. {
  150. pt.X = rc.Width - (setting.Width + 30);
  151. }
  152. setting.Left = pt.X + 20;
  153. setting.Top = pt.Y;
  154. setting.ShowDialog();
  155. }
  156. }
  157. }