using Caliburn.Micro; using MECF.Framework.Common.DataCenter; using MECF.Framework.UI.Client.CenterViews.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; namespace MECF.Framework.UI.Client.Themes.OceanBlue { public partial class TextBoxEx : ResourceDictionary { public bool EnablePopupKeyboard { get; set; } = true; public void OnClick(object sender, MouseButtonEventArgs e) { if (e.StylusDevice != null) { e.Handled = true; return; } if (sender is TextBox) { TextBox textBox = sender as TextBox; if (textBox.Tag != null && textBox.Tag.ToString().Contains("None")) { e.Handled = false; return; } else { e.Handled = true; } string strRet = Show(sender, textBox.Text); if (string.IsNullOrEmpty(strRet)) return; textBox.Text = strRet; } else if (sender is PasswordBox) { PasswordBox passwordBox = sender as PasswordBox; string strRet = Show(sender, passwordBox.Password); if (string.IsNullOrEmpty(strRet)) return; passwordBox.Password = strRet; } } public void TextBox_PreviewTouchDown(object sender, TouchEventArgs e) { if (sender is TextBox) { TextBox textBox = sender as TextBox; string strRet = Show(sender, textBox.Text); if (string.IsNullOrEmpty(strRet)) return; textBox.Text = strRet; } else if (sender is PasswordBox) { PasswordBox passwordBox = sender as PasswordBox; string strRet = Show(sender, passwordBox.Password); if (string.IsNullOrEmpty(strRet)) return; passwordBox.Password = strRet; } } public void OnLoaded(object sender, RoutedEventArgs e) { if (sender is TextBox) { TextBox textBox = sender as TextBox; if (QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard") != null) EnablePopupKeyboard = (bool)QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard"); textBox.IsReadOnly = EnablePopupKeyboard; } } private string Show(object sender, string strDefaultValue) { Control control = sender as Control; string strRet = string.Empty; if (QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard") != null) EnablePopupKeyboard = (bool)QueryDataClient.Instance.Service.GetConfig($"System.EnablePopupKeyboard"); if (!EnablePopupKeyboard) { return string.Empty; } if (control.Tag != null && control.Tag.ToString().Contains("Number")) { NumberKeyboard numberKeyboard = new NumberKeyboard("", strDefaultValue); if (control.Tag.ToString().Contains("SubPanel")) { numberKeyboard.WindowStartupLocation = WindowStartupLocation.CenterScreen; } else { if (control.Tag.ToString().Contains(":")) { var subTagArray = control.Tag.ToString().Split(':'); if (subTagArray.Length > 1) { int keepDecimals = -1; if (int.TryParse(subTagArray[1], out keepDecimals)) { if (keepDecimals != -1) numberKeyboard.KeepDecimals = keepDecimals; } } } var point = control.PointFromScreen(new Point(0, 0)); double x = SystemParameters.WorkArea.Width; double y = SystemParameters.WorkArea.Height; if (-point.Y + control.ActualHeight + 5 + numberKeyboard.Height < y) { numberKeyboard.Top = -point.Y + control.ActualHeight + 5; } else { numberKeyboard.Top = -point.Y - numberKeyboard.Height - 5; } if (-point.X + numberKeyboard.Width < x) { numberKeyboard.Left = -point.X; } else { numberKeyboard.Left = -point.X - (numberKeyboard.Width - control.ActualWidth); } } if ((bool)numberKeyboard.ShowDialog()) strRet = numberKeyboard.ValueString; } else if (control.Tag != null && control.Tag.ToString().Contains("None")) { return string.Empty; } else if (control.Tag != null && control.Tag.ToString().Contains("NotClearFull")) { FullKeyboard fullKeyboard = new FullKeyboard("", strDefaultValue); fullKeyboard.IsFristClick = false; if (control.Tag != null && control.Tag.ToString().Contains("SubPanel")) { fullKeyboard.WindowStartupLocation = WindowStartupLocation.CenterScreen; } else { var point = control.PointFromScreen(new Point(0, 0)); double x = SystemParameters.WorkArea.Width; double y = SystemParameters.WorkArea.Height; if (-point.Y + control.ActualHeight + 5 + fullKeyboard.Height < y) { fullKeyboard.Top = -point.Y + control.ActualHeight + 5; } else { fullKeyboard.Top = -point.Y - fullKeyboard.Height - 5; } if (-point.X + fullKeyboard.Width < x) { fullKeyboard.Left = -point.X; } else { fullKeyboard.Left = -point.X - (fullKeyboard.Width - control.ActualWidth); } } if ((bool)fullKeyboard.ShowDialog()) strRet = fullKeyboard.ValueString; return strRet; } else { FullKeyboard fullKeyboard = new FullKeyboard("", strDefaultValue); if (control.Tag != null && control.Tag.ToString().Contains("SubPanel")) { fullKeyboard.WindowStartupLocation = WindowStartupLocation.CenterScreen; } else { var point = control.PointFromScreen(new Point(0, 0)); double x = SystemParameters.WorkArea.Width; double y = SystemParameters.WorkArea.Height; if (-point.Y + control.ActualHeight + 5 + fullKeyboard.Height < y) { fullKeyboard.Top = -point.Y + control.ActualHeight + 5; } else { fullKeyboard.Top = -point.Y - fullKeyboard.Height - 5; } if (-point.X + fullKeyboard.Width < x) { fullKeyboard.Left = -point.X; } else { fullKeyboard.Left = -point.X - (fullKeyboard.Width - control.ActualWidth); } } if ((bool)fullKeyboard.ShowDialog()) strRet = fullKeyboard.ValueString; } return strRet; } } }