EndPointView.xaml.cs 789 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Text.RegularExpressions;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using Aitex.Core.UI.MVVM;
  6. namespace VirgoUI.Client.Models.Utility.EndPoint
  7. {
  8. /// <summary>
  9. /// EndPointView.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class EndPointView : UserControl
  12. {
  13. public EndPointView()
  14. {
  15. InitializeComponent();
  16. }
  17. private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  18. {
  19. e.Handled = !IsTextAllowed(e.Text);
  20. }
  21. private static bool IsTextAllowed(string text)
  22. {
  23. Regex regex = new Regex("[^0-9.]+"); //regex that matches disallowed text
  24. return !regex.IsMatch(text);
  25. }
  26. }
  27. }