using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; 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 XHandler.View.MethodProperty { /// /// SetVariablePopwin.xaml 的交互逻辑 /// public partial class SetVariablePopwin :Window { public string variablename = ""; public string variablevalue = ""; public SetVariablePopwin(string name,string value) { InitializeComponent(); tbxVariableName.Text = name; tbxVariableValue.Text = value; } private void tbxVariableValue_TextChanged(object sender, TextChangedEventArgs e) { variablevalue = tbxVariableValue.Text; } private void tbxVariableValue_PreviewTextInput(object sender, TextCompositionEventArgs e) { string integerPattern = @"^-?\d+$"; string decimalPattern = @"^-?\d+(\.\d+)?$"; string postfix = ""; if (e.Text == "-") { postfix = "0"; } Regex regex = new Regex(integerPattern); bool integerPatternBool = regex.IsMatch(tbxVariableValue.Text + e.Text + postfix); regex = new Regex(decimalPattern); bool decimalPatternBool = regex.IsMatch(tbxVariableValue.Text + e.Text + postfix); if (e.Text == ".") { decimalPatternBool = regex.IsMatch(tbxVariableValue.Text + e.Text + "0"); } else { } if (!integerPatternBool && !decimalPatternBool) { tbxVariableValue.Text = ""; e.Handled = true; } } private void Button_Click(object sender, RoutedEventArgs e) { this.Close(); } } }