using FujianEarthquake.Common; 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.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace FujianEarthquake.Views { /// /// SystemControlView.xaml 的交互逻辑 /// public partial class SystemControlView : UserControl { public SystemControlView() { InitializeComponent(); this.DataContext = MainWindow.mainViewModel; //串口号 for (int i = 0; i < Tools.GetSerialPort().Length; i++) { this.ShorePortName.Items.Add(Tools.GetSerialPort()[i]); } //波特率 string[] btl = new string[] { "110", "300", "600", "1200", "2400", "4800", "9600", "14400", "19200", "38400", "56000", "57600", "115200", "128000", "256000" }; for (int i = 0; i < btl.Length; i++) { this.ShoreBaudRate.Items.Add(btl[i]); } } private void SetVoltageTB_PreviewTextInput(object sender, TextCompositionEventArgs e) { //e.Handled = !IsTextValidForIntegerOrDecimal(e.Text); string input = e.Text; if (!char.IsDigit(input[0]) && input != "." && !char.IsControl(input[0])) { e.Handled = true; } } private void SetCurrentTB_PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = !IsTextValidForIntegerOrDecimal(e.Text); } private void ProVoltageTB_PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = !IsTextValidForIntegerOrDecimal(e.Text); } private void ProCurrentTB_PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = !IsTextValidForIntegerOrDecimal(e.Text); } private bool IsTextValidForIntegerOrDecimal(string text) { if (string.IsNullOrEmpty(text)) return false; foreach (char c in text) { if (char.IsControl(c) || c == '.') continue; if (!char.IsDigit(c)) return false; } return true; } } }