AITScReadOnlyDoubleRow.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using System.Text.RegularExpressions;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. namespace MECF.Framework.UI.Core.CommonControl
  6. {
  7. /// <summary>
  8. /// AITScReadOnlyDoubleRow.xaml 的交互逻辑
  9. /// </summary>
  10. public partial class AITScReadOnlyDoubleRow : UserControl
  11. {
  12. public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
  13. "Command", typeof(ICommand), typeof(AITScReadOnlyDoubleRow),
  14. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  15. public ICommand Command
  16. {
  17. get
  18. {
  19. return (ICommand)this.GetValue(CommandProperty);
  20. }
  21. set
  22. {
  23. this.SetValue(CommandProperty, value);
  24. }
  25. }
  26. public static readonly DependencyProperty NameWidthProperty = DependencyProperty.Register(
  27. "NameWidth", typeof(int), typeof(AITScReadOnlyDoubleRow),
  28. new FrameworkPropertyMetadata(180, FrameworkPropertyMetadataOptions.AffectsRender));
  29. public int NameWidth
  30. {
  31. get
  32. {
  33. return (int)this.GetValue(NameWidthProperty);
  34. }
  35. set
  36. {
  37. this.SetValue(NameWidthProperty, value);
  38. }
  39. }
  40. public static readonly DependencyProperty FeedbackWidthProperty = DependencyProperty.Register(
  41. "FeedbackWidth", typeof(int), typeof(AITScReadOnlyDoubleRow),
  42. new FrameworkPropertyMetadata(90, FrameworkPropertyMetadataOptions.AffectsRender));
  43. public int FeedbackWidth
  44. {
  45. get
  46. {
  47. return (int)this.GetValue(FeedbackWidthProperty);
  48. }
  49. set
  50. {
  51. this.SetValue(FeedbackWidthProperty, value);
  52. }
  53. }
  54. public static readonly DependencyProperty SetPointWidthProperty = DependencyProperty.Register(
  55. "SetPointWidth", typeof(int), typeof(AITScReadOnlyDoubleRow),
  56. new FrameworkPropertyMetadata(90, FrameworkPropertyMetadataOptions.AffectsRender));
  57. public int SetPointWidth
  58. {
  59. get
  60. {
  61. return (int)this.GetValue(SetPointWidthProperty);
  62. }
  63. set
  64. {
  65. this.SetValue(SetPointWidthProperty, value);
  66. }
  67. }
  68. public static readonly DependencyProperty CommandWidthProperty = DependencyProperty.Register(
  69. "CommandWidth", typeof(int), typeof(AITScReadOnlyDoubleRow),
  70. new FrameworkPropertyMetadata(90, FrameworkPropertyMetadataOptions.AffectsRender));
  71. public int CommandWidth
  72. {
  73. get
  74. {
  75. return (int)this.GetValue(CommandWidthProperty);
  76. }
  77. set
  78. {
  79. this.SetValue(CommandWidthProperty, value);
  80. }
  81. }
  82. public static readonly DependencyProperty ScIdProperty = DependencyProperty.Register(
  83. "ScId", typeof(string), typeof(AITScReadOnlyDoubleRow),
  84. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  85. public string ScId
  86. {
  87. get
  88. {
  89. return (string)this.GetValue(ScIdProperty);
  90. }
  91. set
  92. {
  93. this.SetValue(ScIdProperty, value);
  94. }
  95. }
  96. public static readonly DependencyProperty ScNameProperty = DependencyProperty.Register(
  97. "ScName", typeof(string), typeof(AITScReadOnlyDoubleRow),
  98. new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  99. public string ScName
  100. {
  101. get
  102. {
  103. return (string)this.GetValue(ScNameProperty);
  104. }
  105. set
  106. {
  107. this.SetValue(ScNameProperty, value);
  108. }
  109. }
  110. public static readonly DependencyProperty ScFeedbackProperty = DependencyProperty.Register(
  111. "ScFeedback", typeof(double), typeof(AITScReadOnlyDoubleRow),
  112. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  113. public double ScFeedback
  114. {
  115. get
  116. {
  117. return (double)this.GetValue(ScFeedbackProperty);
  118. }
  119. set
  120. {
  121. this.SetValue(ScFeedbackProperty, value);
  122. }
  123. }
  124. public static readonly DependencyProperty ScSetPointProperty = DependencyProperty.Register(
  125. "ScSetPoint", typeof(double), typeof(AITScReadOnlyDoubleRow),
  126. new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
  127. public double ScSetPoint
  128. {
  129. get
  130. {
  131. return (double)this.GetValue(ScSetPointProperty);
  132. }
  133. set
  134. {
  135. this.SetValue(ScSetPointProperty, value);
  136. }
  137. }
  138. public AITScReadOnlyDoubleRow()
  139. {
  140. InitializeComponent();
  141. }
  142. private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  143. {
  144. e.Handled = !IsTextAllowed(e.Text);
  145. }
  146. private static bool IsTextAllowed(string text)
  147. {
  148. Regex regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text
  149. return !regex.IsMatch(text);
  150. }
  151. private void Button_Click(object sender, RoutedEventArgs e)
  152. {
  153. }
  154. }
  155. }