DataLabel.xaml.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using NEIntelligentControl2.Models.BoostStation;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace NEIntelligentControl2.Views.BoostStation
  17. {
  18. /// <summary>
  19. /// 数据标签
  20. /// </summary>
  21. public partial class DataLabel : UserControl, IBoostStationPoint
  22. {
  23. public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(DataLabel));
  24. public static readonly DependencyProperty IsEditModelProperty = DependencyProperty.Register("IsEditModel", typeof(bool), typeof(DataLabel));
  25. public static readonly DependencyProperty ProportionProperty = DependencyProperty.Register("Proportion", typeof(int), typeof(DataLabel));
  26. public static readonly DependencyProperty InfoProperty = DependencyProperty.Register("Info", typeof(string), typeof(DataLabel));
  27. public bool IsSelected { get => (bool)GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); }
  28. public double Value { get { double.TryParse(Info, out double d); return d; } set => Info = Math.Round(value, 2).ToString(); }
  29. /// <summary>
  30. /// 是否是编辑模式
  31. /// </summary>
  32. public bool IsEditModel { get => (bool)GetValue(IsEditModelProperty); set => SetValue(IsEditModelProperty, value); }
  33. public bool IsTemplete { get; set; }
  34. public string DataTag { get; set; }
  35. public int Proportion { get => (int)GetValue(ProportionProperty); set => SetValue(ProportionProperty, value); }
  36. public string Info { get => GetValue(InfoProperty) as string; set => SetValue(InfoProperty, value); }
  37. public bool IsNegate { get; set; }
  38. public Action<Control> Clicked { get; set; }
  39. public DataLabel()
  40. {
  41. Proportion = 12;
  42. InitializeComponent();
  43. }
  44. private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  45. {
  46. IsSelected = !IsSelected && !IsTemplete && IsEditModel;
  47. Clicked?.Invoke(this);
  48. }
  49. public void Zoom(int times)
  50. {
  51. Proportion += times;
  52. TextBlock tb = new TextBlock();
  53. Binding bd = new Binding("Value");
  54. RelativeSource rs = new RelativeSource() { AncestorType = typeof(UserControl), Mode = RelativeSourceMode.FindAncestor };
  55. bd.RelativeSource = rs;
  56. tb.SetBinding(TextBlock.TextProperty, bd);
  57. tb.FontSize = Proportion;
  58. tb.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
  59. tb.Background = new SolidColorBrush(Color.FromArgb(102, 255, 255, 255));
  60. _GMain.Children.Clear();
  61. _GMain.Children.Add(tb);
  62. }
  63. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  64. {
  65. Info = "-.--";
  66. }
  67. }
  68. }