TextBoxEx.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Caliburn.Micro;
  2. using MECF.Framework.Common.DataCenter;
  3. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Input;
  12. namespace MECF.Framework.UI.Client.Themes.lightgreen
  13. {
  14. public partial class TextBoxEx : ResourceDictionary
  15. {
  16. public bool EnablePopupKeyboard { get; set; } = true;
  17. public void OnClick(object sender, MouseButtonEventArgs e)
  18. {
  19. if (sender is TextBox)
  20. {
  21. TextBox textBox = sender as TextBox;
  22. string strRet = Show(sender, textBox.Text);
  23. if (string.IsNullOrEmpty(strRet)) return;
  24. textBox.Text = strRet;
  25. }
  26. else if (sender is PasswordBox)
  27. {
  28. PasswordBox passwordBox = sender as PasswordBox;
  29. string strRet = Show(sender, passwordBox.Password);
  30. if (string.IsNullOrEmpty(strRet)) return;
  31. passwordBox.Password = strRet;
  32. }
  33. }
  34. private string Show(object sender, string strDefaultValue)
  35. {
  36. Control control = sender as Control;
  37. string strRet = string.Empty;
  38. if(QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard") != null)
  39. EnablePopupKeyboard = (bool)QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard");
  40. if (!EnablePopupKeyboard) { return string.Empty; }
  41. if (control.Tag != null && control.Tag.ToString().Contains("Number"))
  42. {
  43. NumberKeyboard numberKeyboard = new NumberKeyboard("", strDefaultValue);
  44. if (control.Tag.ToString().Contains("SubPanel"))
  45. {
  46. numberKeyboard.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  47. }
  48. else
  49. {
  50. var point = control.PointFromScreen(new Point(0, 0));
  51. double x = SystemParameters.WorkArea.Width;
  52. double y = SystemParameters.WorkArea.Height;
  53. if (-point.Y + control.ActualHeight + 5 + numberKeyboard.Height < y)
  54. {
  55. numberKeyboard.Top = -point.Y + control.ActualHeight + 5;
  56. }
  57. else
  58. {
  59. numberKeyboard.Top = -point.Y - numberKeyboard.Height - 5;
  60. }
  61. if (-point.X + numberKeyboard.Width < x)
  62. {
  63. numberKeyboard.Left = -point.X;
  64. }
  65. else
  66. {
  67. numberKeyboard.Left = -point.X - (numberKeyboard.Width - control.ActualWidth);
  68. }
  69. }
  70. if ((bool)numberKeyboard.ShowDialog()) strRet = numberKeyboard.ValueString;
  71. }
  72. else if (control.Tag != null && control.Tag.ToString().Contains("None"))
  73. {
  74. return string.Empty;
  75. }
  76. else
  77. {
  78. FullKeyboard fullKeyboard = new FullKeyboard("", strDefaultValue);
  79. if (control.Tag != null && control.Tag.ToString().Contains("SubPanel"))
  80. {
  81. fullKeyboard.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  82. }else
  83. {
  84. var point = control.PointFromScreen(new Point(0, 0));
  85. double x = SystemParameters.WorkArea.Width;
  86. double y = SystemParameters.WorkArea.Height;
  87. if (-point.Y + control.ActualHeight + 5 + fullKeyboard.Height < y)
  88. {
  89. fullKeyboard.Top = -point.Y + control.ActualHeight + 5;
  90. }
  91. else
  92. {
  93. fullKeyboard.Top = -point.Y - fullKeyboard.Height - 5;
  94. }
  95. if (-point.X + fullKeyboard.Width < x)
  96. {
  97. fullKeyboard.Left = -point.X;
  98. }
  99. else
  100. {
  101. fullKeyboard.Left = -point.X - (fullKeyboard.Width - control.ActualWidth);
  102. }
  103. }
  104. if ((bool)fullKeyboard.ShowDialog()) strRet = fullKeyboard.ValueString;
  105. }
  106. return strRet;
  107. }
  108. }
  109. }