ProcessConfigView.xaml.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Aitex.Core.UI.MVVM;
  16. using Aitex.Triton160.UI.ViewModel;
  17. namespace Aitex.Triton160.UI.Views
  18. {
  19. /// <summary>
  20. /// ConfigView.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class ProcessConfigView : UserControl
  23. {
  24. public ProcessConfigView()
  25. {
  26. InitializeComponent();
  27. this.DataContext = new ProcessConfigViewModel();
  28. this.IsVisibleChanged += ProcessConfigView_IsVisibleChanged;
  29. }
  30. void ProcessConfigView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  31. {
  32. (this.DataContext as TimerViewModelBase).EnableTimer(this.IsVisible);
  33. }
  34. private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  35. {
  36. e.Handled = !IsTextAllowed(e.Text);
  37. }
  38. private static bool IsTextAllowed(string text)
  39. {
  40. Regex regex = new Regex("[^0-9.]+"); //regex that matches disallowed text
  41. return !regex.IsMatch(text);
  42. }
  43. }
  44. }