| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- using SHJX.Service.Common.Utils;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace SHJX.Service.Librarys.MainLibrarys
- {
- /// <summary>
- /// UserControl1.xaml 的交互逻辑
- /// </summary>
- public partial class DetailElement : UserControl
- {
- public string CurrentName
- {
- get => (string)GetValue(CurrentNameProperty);
- set => SetValue(CurrentNameProperty, value);
- }
- public static readonly DependencyProperty CurrentNameProperty =
- DependencyProperty.Register(
- nameof(CurrentName), typeof(string),
- typeof(DetailElement), new UIPropertyMetadata(string.Empty, (obj, args) =>
- {
- var control = obj as DetailElement;
- control.Name = args.NewValue.ToString();
- }));
- #region 控件编号
- public string CurrentTagNo
- {
- get => (string)GetValue(CurrentTagNoProperty);
- set => SetValue(CurrentTagNoProperty, value);
- }
- public static readonly DependencyProperty CurrentTagNoProperty =
- DependencyProperty.Register(
- nameof(CurrentTagNo), typeof(string),
- typeof(DetailElement), new UIPropertyMetadata(string.Empty, CurrentTagNoPropertyChangedCallback)
- );
- private static void CurrentTagNoPropertyChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args)
- {
- var control = obj as DetailElement;
- var path = control.btn_TagNo;
- path.Content = args.NewValue.ToString();
- }
- #endregion
- #region 顶部详细信息
- public string CurrentDetailInfo
- {
- get => (string)GetValue(CurrentDetailInfoProperty);
- set => SetValue(CurrentDetailInfoProperty, value);
- }
- public static readonly DependencyProperty CurrentDetailInfoProperty =
- DependencyProperty.Register(
- nameof(CurrentDetailInfo), typeof(string),
- typeof(DetailElement), new UIPropertyMetadata(string.Empty, CurrentDetailInfoChangedCallback)
- );
- private static void CurrentDetailInfoChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args)
- {
- var control = obj as DetailElement;
- var path = control.txt_detail;
- path.Text = args.NewValue.ToString();
- }
- #endregion
- #region 顶部颜色
- public string CurrentTagColor
- {
- get => (string)GetValue(CurrentTagColorProperty);
- set => SetValue(CurrentTagColorProperty, value);
- }
- public static readonly DependencyProperty CurrentTagColorProperty =
- DependencyProperty.Register(
- nameof(CurrentTagColor), typeof(string),
- typeof(DetailElement), new UIPropertyMetadata(string.Empty, CurrentTagColorChangedCallBack)
- );
- private static void CurrentTagColorChangedCallBack(DependencyObject obj, DependencyPropertyChangedEventArgs args)
- {
- var control = obj as DetailElement;
- var path = control?.UserControlTag;
- path.Background = args.NewValue.ToString().ConvertToBrush();
- }
- #endregion
- #region 体积
- public string CurrentVolume
- {
- get => (string)GetValue(CurrentVolumeProperty);
- set => SetValue(CurrentVolumeProperty, value);
- }
- public static readonly DependencyProperty CurrentVolumeProperty =
- DependencyProperty.Register(
- nameof(CurrentVolume), typeof(string),
- typeof(DetailElement), new UIPropertyMetadata(string.Empty, CurrentVolumeChangedCallback)
- );
- private static void CurrentVolumeChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args)
- {
- var control = obj as DetailElement;
- var path = control?.txt_volume;
- path.Text = args.NewValue.ToString();
- }
- #endregion
- #region 结果
- public string CurrentResult
- {
- get => (string)GetValue(CurrentResultProperty);
- set => SetValue(CurrentResultProperty, value);
- }
- public static readonly DependencyProperty CurrentResultProperty =
- DependencyProperty.Register(
- nameof(CurrentResult), typeof(string),
- typeof(DetailElement), new UIPropertyMetadata(string.Empty, CurrentResultChangedCallback)
- );
- private static void CurrentResultChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args)
- {
- var control = obj as DetailElement;
- var path = control?.txt_result;
- path.Text = args.NewValue?.ToString();
- }
- #endregion
- public DetailElement()
- {
- InitializeComponent();
- }
- private void ChooseMode_Click(object sender, RoutedEventArgs e)
- {
- GeneralTransform gt = ChooseMode.TransformToAncestor(Application.Current.MainWindow!);
- Point pt = gt.Transform(new Point(0, 0));
- Rect rc = SystemParameters.WorkArea;//获取工作区大小
- if (pt.Y + 315 > rc.Height)
- {
- pt.Y = rc.Height - 315;
- }
- if (pt.X + 255 > rc.Width)
- {
- pt.X = rc.Width - 255;
- }
- ModeSetting setting = new(CurrentDetailInfo, CurrentTagColor, Name)
- {
- WindowStartupLocation = WindowStartupLocation.Manual,
- Left = pt.X + 20,
- Top = pt.Y
- };
- setting.ShowDialog();
- }
- }
- }
|