using System.Windows; using System.Windows.Media; using System.Windows.Controls; using SHJX.Service.Common.UserColor; using SHJX.Service.Common.Utils; namespace SHJX.Service.Library.Views { /// /// UserControl1.xaml 的交互逻辑 /// public partial class SampleDetailControl : UserControl { #region public string CurrentName { get => (string)GetValue(CurrentNameProperty); set => SetValue(CurrentNameProperty, value); } public static readonly DependencyProperty CurrentNameProperty = DependencyProperty.Register( nameof(CurrentName), typeof(string), typeof(SampleDetailControl), new UIPropertyMetadata(string.Empty, (obj, args) => { var control = obj as SampleDetailControl; control.Name = args.NewValue.ToString(); })); #endregion #region 控件编号 public string CurrentTagNo { get => (string)GetValue(CurrentTagNoProperty); set => SetValue(CurrentTagNoProperty, value); } public static readonly DependencyProperty CurrentTagNoProperty = DependencyProperty.Register( nameof(CurrentTagNo), typeof(string), typeof(SampleDetailControl), new UIPropertyMetadata(string.Empty, CurrentTagNoChangedCallback) ); private static void CurrentTagNoChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args) { var control = obj as SampleDetailControl; 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(SampleDetailControl), new UIPropertyMetadata(string.Empty, CurrentDetailInfoChangedCallback) ); private static void CurrentDetailInfoChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args) { var control = obj as SampleDetailControl; 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(SampleDetailControl), new UIPropertyMetadata(string.Empty, CurrentTagColorChangedCallBack) ); private static void CurrentTagColorChangedCallBack(DependencyObject obj, DependencyPropertyChangedEventArgs args) { var control = obj as SampleDetailControl; 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(SampleDetailControl), new UIPropertyMetadata(string.Empty, CurrentVolumeChangedCallback) ); private static void CurrentVolumeChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args) { var control = obj as SampleDetailControl; 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(SampleDetailControl), new UIPropertyMetadata(string.Empty, (obj, args) => { var control = obj as SampleDetailControl; var path = control?.txt_result; path.Text = args.NewValue.ToString(); })); #endregion #region ResultColor public string ResultColor { get => (string)GetValue(ResultColorProperty); set => SetValue(ResultColorProperty, value); } public static readonly DependencyProperty ResultColorProperty = DependencyProperty.Register( nameof(ResultColor), typeof(string), typeof(SampleDetailControl), new UIPropertyMetadata("#000000", ResultColorChangedCallback)); private static void ResultColorChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs args) { var control = obj as SampleDetailControl; var path = control.txt_result; path.Foreground = args.NewValue.ToString().ConvertToBrush(); } #endregion public SampleDetailControl() { 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;//获取工作区大小 ModeSetting setting = new(Name) { WindowStartupLocation = WindowStartupLocation.Manual }; if (pt.Y + setting.Height > rc.Height) { pt.Y = rc.Height - (setting.Height + 10); } if (pt.X + setting.Width > rc.Width) { pt.X = rc.Width - (setting.Width + 30); } setting.Left = pt.X + 20; setting.Top = pt.Y; setting.ShowDialog(); } } }