using SHJX.Service.Common.Utils; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace SHJX.Service.Librarys.MainLibrarys { /// /// UserControl1.xaml 的交互逻辑 /// 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(); } } }