DiagnoseView.xaml.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.Jet.UI.Views
  18. {
  19. /// <summary>
  20. /// DiagnoseView.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class DiagnoseView : UserControl
  23. {
  24. public DiagnoseView()
  25. {
  26. InitializeComponent();
  27. this.DataContext = new DiagnoseViewModel();
  28. this.IsVisibleChanged += LeakCheckView_IsVisibleChanged;
  29. }
  30. private void LeakCheckView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  31. {
  32. (this.DataContext as TimerViewModelBase).EnableTimer(this.IsVisible);
  33. if (this.IsVisible)
  34. (this.DataContext as DiagnoseViewModel).UpdateLeakCheckResult();
  35. }
  36. private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  37. {
  38. e.Handled = !IsTextAllowed(e.Text);
  39. }
  40. private static bool IsTextAllowed(string text)
  41. {
  42. Regex regex = new Regex("[^0-9.]+"); //regex that matches disallowed text
  43. return !regex.IsMatch(text);
  44. }
  45. }
  46. }