| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 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
- {
- /// <summary>
- /// UserControl1.xaml 的交互逻辑
- /// </summary>
- 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();
- }
- }
- }
|