MainWindow.xaml.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Text;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Data;
  5. using System.Windows.Documents;
  6. using System.Windows.Input;
  7. using System.Windows.Media;
  8. using System.Windows.Media.Imaging;
  9. using System.Windows.Navigation;
  10. using System.Windows.Shapes;
  11. namespace vStationTool
  12. {
  13. /// <summary>
  14. /// Interaction logic for MainWindow.xaml
  15. /// </summary>
  16. public partial class MainWindow : Window
  17. {
  18. public MainWindow()
  19. {
  20. InitializeComponent();
  21. }
  22. private void portNum_PreviewTextInput(object sender, TextCompositionEventArgs e)
  23. {
  24. e.Handled = !char.IsDigit(e.Text, e.Text.Length - 1);
  25. }
  26. private void ipAddress_PreviewTextInput(object sender, TextCompositionEventArgs e)
  27. {
  28. e.Handled = !IsValidIpChar(e.Text);
  29. }
  30. private bool IsValidIpChar(string text)
  31. {
  32. // 检查是否是数字或.
  33. return char.IsDigit(text, 0) || text == ".";
  34. }
  35. }
  36. }