TextBoxEx3.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using MECF.Framework.Common.DataCenter;
  2. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  3. using MECF.Framework.UI.Client.ClientViews.Dialogs;
  4. using OpenSEMI.ClientBase;
  5. using OpenSEMI.Ctrlib.Controls;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Input;
  14. using TextBox2 = OpenSEMI.Ctrlib.Controls.TextBoxEx;
  15. namespace MECF.Framework.UI.Client.Themes.OceanBlue
  16. {
  17. public partial class TextBoxEx3 : ResourceDictionary
  18. {
  19. public bool EnablePopupKeyboard { get; set; } = true;
  20. public void OnClick(object sender, MouseButtonEventArgs e)
  21. {
  22. if (e.StylusDevice != null)
  23. {
  24. e.Handled = true;
  25. return;
  26. }
  27. e.Handled = true;
  28. if (sender is TextBox2)
  29. {
  30. TextBox2 textBox = sender as TextBox2;
  31. string strRet = Show(sender, textBox.Text);
  32. if (string.IsNullOrEmpty(strRet)) return;
  33. if (strRet != textBox.Text)
  34. {
  35. if (!textBox.AllowIsOutOfRangeSaveChange && textBox.IsOutOfRange(double.Parse(strRet)))
  36. {
  37. DialogBox.ShowInfo($"Out Of Range{textBox.MinValue}-{textBox.MaxValue}");
  38. return;
  39. }
  40. textBox.TextSaved = false;
  41. textBox.Text = strRet;
  42. }
  43. }
  44. else if (sender is PasswordBox)
  45. {
  46. PasswordBox passwordBox = sender as PasswordBox;
  47. string strRet = Show(sender, passwordBox.Password);
  48. if (string.IsNullOrEmpty(strRet)) return;
  49. passwordBox.Password = strRet;
  50. }
  51. }
  52. public void TextBox_PreviewTouchDown(object sender, TouchEventArgs e)
  53. {
  54. if (sender is TextBox2)
  55. {
  56. TextBox2 textBox = sender as TextBox2;
  57. string strRet = Show(sender, textBox.Text);
  58. if (string.IsNullOrEmpty(strRet)) return;
  59. if (strRet != textBox.Text)
  60. {
  61. if (!textBox.AllowIsOutOfRangeSaveChange && textBox.IsOutOfRange(double.Parse(strRet)))
  62. {
  63. DialogBox.ShowInfo($"Out Of Range{textBox.MinValue}-{textBox.MaxValue}");
  64. return;
  65. }
  66. textBox.TextSaved = false;
  67. textBox.Text = strRet;
  68. }
  69. }
  70. else if (sender is PasswordBox)
  71. {
  72. PasswordBox passwordBox = sender as PasswordBox;
  73. string strRet = Show(sender, passwordBox.Password);
  74. if (string.IsNullOrEmpty(strRet)) return;
  75. passwordBox.Password = strRet;
  76. }
  77. }
  78. public void OnLoaded(object sender, RoutedEventArgs e)
  79. {
  80. if (sender is TextBox2)
  81. {
  82. TextBox2 textBox = sender as TextBox2;
  83. if (QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard") != null)
  84. EnablePopupKeyboard = (bool)QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard");
  85. textBox.IsReadOnly = EnablePopupKeyboard;
  86. }
  87. }
  88. private string Show(object sender, string strDefaultValue)
  89. {
  90. TextBox2 control = sender as TextBox2;
  91. string strRet = string.Empty;
  92. if (QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard") != null)
  93. EnablePopupKeyboard = (bool)QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard");
  94. if (!EnablePopupKeyboard) { return string.Empty; }
  95. if (control.Tag != null && control.Tag.ToString().Contains("Number"))
  96. {
  97. NumberKeyboard numberKeyboard = new NumberKeyboard("", strDefaultValue);
  98. numberKeyboard.KeepDecimals = control.KeepDecimals;
  99. var point = control.PointFromScreen(new Point(0, 0));
  100. double x = SystemParameters.WorkArea.Width;
  101. double y = SystemParameters.WorkArea.Height;
  102. if (-point.Y + control.ActualHeight + 5 + numberKeyboard.Height < y)
  103. {
  104. numberKeyboard.Top = -point.Y + control.ActualHeight + 5;
  105. }
  106. else
  107. {
  108. numberKeyboard.Top = -point.Y - numberKeyboard.Height - 5;
  109. }
  110. if (-point.X + numberKeyboard.Width < x)
  111. {
  112. numberKeyboard.Left = -point.X;
  113. }
  114. else
  115. {
  116. numberKeyboard.Left = -point.X - (numberKeyboard.Width - control.ActualWidth);
  117. }
  118. if ((bool)numberKeyboard.ShowDialog())
  119. {
  120. strRet = numberKeyboard.ValueString;
  121. }
  122. }
  123. //if (control.Tag != null && control.Tag.ToString().Equals("Number"))
  124. //{
  125. // var point = control.PointFromScreen(new Point(0, 0));
  126. // double x = SystemParameters.WorkArea.Width;
  127. // double y = SystemParameters.WorkArea.Height;
  128. // NumberKeyborardNoMinus numberKeyboard = new NumberKeyborardNoMinus("", strDefaultValue,true,control.MaxValue,control.MinValue);
  129. // if (-point.Y + control.ActualHeight + 5 + numberKeyboard.Height < y)
  130. // {
  131. // numberKeyboard.Top = -point.Y + control.ActualHeight + 5;
  132. // }
  133. // else
  134. // {
  135. // numberKeyboard.Top = -point.Y - numberKeyboard.Height - 5;
  136. // }
  137. // if (-point.X + numberKeyboard.Width < x)
  138. // {
  139. // numberKeyboard.Left = -point.X;
  140. // }
  141. // else
  142. // {
  143. // numberKeyboard.Left = -point.X - (numberKeyboard.Width - control.ActualWidth);
  144. // }
  145. // if ((bool)numberKeyboard.ShowDialog()) strRet = numberKeyboard.ValueString;
  146. //}
  147. else if (control.Tag != null && control.Tag.ToString().Contains("None"))
  148. {
  149. return string.Empty;
  150. }
  151. else
  152. {
  153. FullKeyboard fullKeyboard = new FullKeyboard("", strDefaultValue);
  154. var point = control.PointFromScreen(new Point(0, 0));
  155. double x = SystemParameters.WorkArea.Width;
  156. double y = SystemParameters.WorkArea.Height;
  157. if (-point.Y + control.ActualHeight + 5 + fullKeyboard.Height < y)
  158. {
  159. fullKeyboard.Top = -point.Y + control.ActualHeight + 5;
  160. }
  161. else
  162. {
  163. fullKeyboard.Top = -point.Y - fullKeyboard.Height - 5;
  164. }
  165. if (-point.X + fullKeyboard.Width < x)
  166. {
  167. fullKeyboard.Left = -point.X;
  168. }
  169. else
  170. {
  171. fullKeyboard.Left = -point.X - (fullKeyboard.Width - control.ActualWidth);
  172. }
  173. if ((bool)fullKeyboard.ShowDialog()) strRet = fullKeyboard.ValueString;
  174. }
  175. return strRet;
  176. }
  177. }
  178. }