DetailElement.xaml.cs 5.6 KB

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